【发布时间】:2016-05-02 05:41:32
【问题描述】:
我的主页模板有一个加载功能,非常适合订阅用户收藏。不幸的是,加载占用了整个页面,我想在等待用户加载的同时显示一些一般信息。
我已经在我的注册模板中使用 ReactiveVar 实现了这个功能,效果很好。
这就是那里的做法:
Template.signup.onCreated(function() {
Template.instance().isLoading = new ReactiveVar(false);
});
Template.signup.helpers({
isLoading() {
return Template.instance().isLoading.get();
}
});
Template.signup.events({
'submit #signup-form': function(event, template) {
// Not important stuff here
template.isLoading.set(true);
Accounts.createUser({
// More not important stuff here
}, function(err) {
// Even more not important stuff here
template.isLoading.set(false);
})
}
});
然后在模板中我有这个:
<template name="signup>
{{#unless isLoading}}
<!-- Stuff -->
{{else}}
<!-- More Stuff -->
{{> loading}}
{{/unless}}
</template>
这非常有效,但我想在我订阅用户的主页上做同样的事情。有没有办法做类似的事情?我已经设置了主页模板调用和东西。但我不知道如何执行加载用户数据的模板事件。
这就是我基本上拥有的:
Template.home.onCreated(function() {
Template.instance().isLoading = new ReactiveVar(false);
});
Template.home.helpers({
user: function() {
return Meteor.users.find({});
},
isLoading() {
return Template.instance().isLoading.get();
}
});
Template.home.events({
//What do I do here????
});
感谢我能得到的任何帮助:)
编辑:这是我的 Meteor 发布代码:
Meteor.publish('users', function() {
return Meteor.users.find({}, {fields: {username: 1, emails: 1, profile: 1}});
});
【问题讨论】:
标签: javascript templates meteor loading reactive-programming