我构建了应用程序,从 mongodb 加载初始数据集需要时间,我想显示加载 gif 直到数据加载完成。你能帮我做这件事吗?
Use Session
在 - 的里面onReady()
的回调Meteor.subscribe()
函数,当订阅完成时调用。
Meteor.subscribe('subscribe_to_this', function onReady(){
// set a session key to true to indicate that the subscription is completed.
Session.set('subscription_completed', true);
});
然后使该会话值从模板助手返回,如下所示:
Template.myTemplate.isSubscriptionComplete = function(){
return Session.get('subscription_completed');
}
现在,在您的 html 中,如果数据未加载,则可以轻松显示加载程序;如果数据已完成加载,则可以轻松呈现模板。
<template name="myTemplate">
{{#if isSubscriptionComplete }}
<!-- Data loading is done, so render your template here -->
{{> yourFinalTemplate}}
{{else}}
<!-- Data loading still remaining, so display loader here -->
<img src="images/load.gif">
{{/if}}
</template>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)