Meteorjs 加载消息 [英] Meteorjs loading message

查看:28
本文介绍了Meteorjs 加载消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I built the application and it is taking time to load the initial set of data from mongodb and I want to show the loadin gif till the data loading is done. Could you please help me in doing this?

推荐答案

Meteor.subscribe()<的 onReady() 回调中使用 Session/code> 函数,订阅完成时调用.

Use Session inside the onReady() callback of the Meteor.subscribe() function, which is invoked when the subscription is completed.

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);
});

然后使这个会话值从你的模板助手返回:

Then make this session value to be returned from your template helper as:

Template.myTemplate.isSubscriptionComplete = function(){
     return Session.get('subscription_completed'); 
}

现在在您的 html 中,如果数据未加载或呈现模板(如果数据已完成加载),则很容易显示加载器.

Now in your html, it is easy to display a loader if data is not loaded or to render a template, if the data has completed loading.

<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>

这篇关于Meteorjs 加载消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆