问题描述
我有一些订阅需要在用户更改角色时刷新.由于用户现在有一个新角色,我需要重新发布订阅,因为他们考虑了角色.这是我正在尝试做的:
I have some subscriptions I need to refresh when a user changes roles. Since the user now has a new role I need to republish the subscriptions as they take role into account. Here is what I'm attempting to do:
Tracker.autorun(function(){
Meteor.users.find({_id: Meteor.userId()}, {fields: {"roles": 1}});
console.log("You changed roles, republishing data");
Meteor.subscribe('pendingUsers');
});
我正在使用 alanning:roles.它似乎在某些情况下有效,但在其他情况下无效.不会触发此运行的一种情况是当我从流星外壳"更改用户角色时.我究竟做错了什么?有没有更好的方法来做到这一点?
I'm using alanning:roles. It seems to work in some situations but not others. One situation that doesn't trigger this to run is when I alter the users roles from "meteor shell". What am I doing wrong? Is there a better way to do this?
推荐答案
您需要在 subscribe()
中进行一些更改.请参阅文档:
You need to make something change within your subscribe()
. See docs:
但是,如果您的 run 函数的下一次迭代订阅了相同的记录集(相同的名称和参数),Meteor 足够聪明,可以跳过浪费的取消订阅/重新订阅.
这篇关于每次用户更改角色时运行订阅的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!