Meteorjs加载消息
我构建了应用程序,从mongodb加载初始数据集需要时间,我希望在数据加载完成之前以gif格式显示加载。您能帮我做这件事吗?这可以通过会话变量来完成。这只是一个开始的示例: 在客户端代码中:Meteorjs加载消息,meteor,Meteor,我构建了应用程序,从mongodb加载初始数据集需要时间,我希望在数据加载完成之前以gif格式显示加载。您能帮我做这件事吗?这可以通过会话变量来完成。这只是一个开始的示例: 在客户端代码中: var yourData; Meteor.startup(function() { Session.set("dataLoaded", false); }); ... // Load your initial data yourData = SampleCollection.find(quer
var yourData;
Meteor.startup(function() {
Session.set("dataLoaded", false);
});
...
// Load your initial data
yourData = SampleCollection.find(query).fetch();
Session.set("dataLoaded", true);
示例模板:
<template name="main">
{{#if dataLoaded}}
<h1>Welcome to my application!</h1>
Your data:
{{#each yourData}}
...
{{/each}}
{{else}
<div>Loading data...</div>
{{/if}}
</template>
这可以通过会话变量来完成。这只是一个开始的示例: 在客户端代码中:
var yourData;
Meteor.startup(function() {
Session.set("dataLoaded", false);
});
...
// Load your initial data
yourData = SampleCollection.find(query).fetch();
Session.set("dataLoaded", true);
示例模板:
<template name="main">
{{#if dataLoaded}}
<h1>Welcome to my application!</h1>
Your data:
{{#each yourData}}
...
{{/each}}
{{else}
<div>Loading data...</div>
{{/if}}
</template>
在
Meteor.subscribe()
函数的onReady()
回调中使用Session
,该函数在订阅完成时调用
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>
{{#如果isSubscriptionComplete}
{{>yourFinalTemplate}
{{else}
{{/if}
在Meteor.subscribe()
函数的onReady()
回调中使用Session
,该函数在订阅完成时调用
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>
{{#如果isSubscriptionComplete}
{{>yourFinalTemplate}
{{else}
{{/if}
Exact duplicate of the Exact duplicate of the代替创建模板助手,我们可以通过添加css类来实现吗?i、 e如果Session.get(“subscription_completed”)为true$(.main container”).addClass(“loading”)else$(.main container”).addClass(“loading”)
我们可以通过添加css类来代替创建模板帮助程序吗?i、 e如果Session.get(“subscription_completed”)为true$(.main container”).addClass(“loading”)否则$(.main container”).addClass(“loading”)