每次用户更改角色时运行订阅 [英] Running a subscription each time user changes roles

查看:38
本文介绍了每次用户更改角色时运行订阅的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些订阅需要在用户更改角色时刷新.由于用户现在有一个新角色,我需要重新发布订阅,因为他们考虑了角色.这是我正在尝试做的:

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 足够聪明,可以跳过浪费的取消订阅/重新订阅.

However, if the next iteration of your run function subscribes to the same record set (same name and parameters), Meteor is smart enough to skip a wasteful unsubscribe/resubscribe.

这篇关于每次用户更改角色时运行订阅的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆