【发布时间】:2016-05-19 05:48:20
【问题描述】:
我正在尝试通过一种方法向 Meteor.Users 添加自定义“isContributor”字段,但不知何故它没有添加该字段。 (我什至在对谁可以进行此更新进行任何安全检查之前就在谈论)。
在客户端我有以下事件:
Template.Articles.events({
'click #BeContributor': function() {
userId = Meteor.userId();
Meteor.call('setContributorState', userId);
}
});
在 server/main.js 中如下:
Meteor.methods({
setContributorState: function(userId) {
Meteor.users.update(userId, {
$set: {
isContributor: true
}
});
}
});
不知何故,它不会为我的用户添加该字段。没有控制台或服务器错误。我想我错过了添加该领域的权利。有什么想法吗?
提前致谢。
--- 编辑 ---
实际上该方法有效,但我没有发布结果,因此我无法在 MeteorToys 中检查该字段是否已更新。通过以下出版物,它可以工作:
Meteor.publish(null, function(){
return Meteor.users.find({_id: this.userId}, {fields: {isContributor: 1}});
});
【问题讨论】:
-
在你的服务器方法中尝试
console.log来检查它是否真的被调用了。 -
刚刚检查过:方法被调用并且 UserId 在那之前被正确执行。更新似乎不起作用。
标签: javascript meteor methods