在函数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);
});
Run Code Online (Sandbox Code Playgroud)
然后从模板助手返回此会话值,如下所示:
Template.myTemplate.isSubscriptionComplete = function(){
return Session.get('subscription_completed');
}
Run Code Online (Sandbox Code Playgroud)
现在在你的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>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
921 次 |
| 最近记录: |