Meteorjs加载消息

Ram*_*amu 1 meteor

我构建了应用程序,它需要时间从mongodb加载初始数据集,我想显示loadin gif直到数据加载完成.你能帮我这么做吗?

soh*_*ifa 8

在函数SessiononReady()回调中使用,该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)