0
我有一個加載函數用於我的家庭模板,它非常適合訂閱用戶集合。不幸的是,加載佔用了整個頁面,我希望在等待用戶加載時顯示一些常規信息。流星:使用ReactiveVar創建一個加載小部件,用於訂閱用戶集合
我已經在我的創建帳戶函數中使用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.publish('users', function() {
return Meteor.users.find({}, {fields: {username: 1, emails: 1, profile: 1}});
});
的不運行,在else語句運行的代碼:/ –
嗯,你是專門試圖讓所有的用戶在家庭信息或只是當前登錄在用戶? –
是的我試圖讓每一個存在的用戶。 –