Meteor:如何使更新 Meteor.user 字段具有响应性
Meteor: How do i make Updating Meteor.user fields reactive?
我有一组称为"类别"的对象,其中有属于该类别的帖子。用户可以通过单击获取该类别对象中的数据的按钮来"关注"类别,最重要的是,帖子将它们放在Meteor.users中的一个字段中。就目前而言,用户仅获得用户单击按钮时可用的帖子。
我该如何做到这一点,以便当他们"关注"一个类别时,在点击事件已经完成后,稍后出现的任何新帖子都将自动推送到他们的用户数据。换句话说,如何使这个过程是被动的?
客户/类别.js
Template.CategoriesMain.events({
'click .toggle-category': function(e){
var ob = $(e.target).parent().find("div").text();
var id = $.makeArray( ob );
console.log(id);
e.preventDefault();
Meteor.call('addingCategory', id, function(error, user){ console.log(id)});
}
});
服务器/类别.js
Meteor.publish("userData", function () {
if (this.userId) {
return Meteor.users.find({_id: this.userId},
{fields: {'name': 1}});
} else {
this.ready();
}
});
我可以用自动运行做点什么吗?
Template.CategoriesMain.events({
'click .toggle-category': function(e){
autorun(function() {
var ob = $(e.target).parent().find("div").text();
var id = $.makeArray( ob );
console.log(id);
e.preventDefault();
Meteor.call('addingCategory', id, function(error, user){ console.log(id)});
}
});
});
目前无法获取它,但请尝试
Meteor.publish("userData", function () { if (this.userId) { 返回 Meteor.users.find({_id: this.userId}, {字段: {'名称': 1}}); } else { 返回空值; } this.ready();});
相关文章:
- Meteor如何接收HTTP请求
- Meteor-将选定窗体中的对象添加到集合中
- 如何将getJson的响应保存在全局变量中
- Meteor上的启动页面
- 如何使用Spring MVC将Facebook返回的响应数据保存在Java类中
- 正在分析Meteor中的错误服务器响应
- 如何等待用户对Meteor AutoForm提交的响应
- Meteor中没有Collection.fund的响应式更新
- Meteor Restivus:飞行前响应中的访问控制允许方法不允许方法PUT
- 响应变量来捕获用户输入(Meteor)
- Meteor:响应式辅助函数.相关的选择
- 在meteor.js中实现响应式按钮的最佳方法
- 如何在Meteor中为带有输入单元格表的表单做响应式绑定?
- 如何使Meteor响应式更新“时间since”;字符串
- 从Meteor中的另一个模板获取响应变量
- 用meteor.js响应式调用js函数/事件
- Meteor:响应式连接公开中间数据
- 在Meteor中创建一个响应式模板助手
- Meteor:如何使更新 Meteor.user 字段具有响应性
- 在 Meteor.js 中获取响应标头