gpt4 book ai didi

javascript - Meteor:使用 ReactiveVar 创建一个加载小部件来订阅用户集合

转载 作者:行者123 更新时间:2023-12-03 07:50:45 25 4
gpt4 key购买 nike

我的主页模板有一个加载功能,该功能非常适合订阅用户集合。不幸的是,加载占用了整个页面,我想在等待用户加载时显示一些一般信息。

我已经在我的创建帐户功能中使用 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}});
});

最佳答案

我认为您想使用 Blaze 助手 Template.subscriptionsReady:

<template name="home">
{{#if Template.subscriptionsReady}}
<!-- Your template code -->
{{else}}
<!-- Your loading code -->
{{/if}}
</template>

以下是相关文档的链接:http://docs.meteor.com/#/full/Blaze-TemplateInstance-subscribe

关于javascript - Meteor:使用 ReactiveVar 创建一个加载小部件来订阅用户集合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35000644/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com