Ale*_*yth 15 javascript publish userid meteor
在我的一个Meteor.publish()功能中,this.userId具有的价值undefined.我不能打电话,Meteor.userId()因为它在发布功能中不可用.你userId现在应该怎么样?
ric*_*ilv 69
有四种可能性:
没有用户登录.
您正在从服务器调用该方法,因此将没有与该调用相关联的用户(除非您从另一个将用户绑定到其环境的函数调用它,如另一个方法或订阅函数).
您甚至没有安装基于帐户的软件包(或任何加载项).我只是为了完整性而包含这个.
您正在使用ES6中的箭头功能.
Meteor.publish('invoices', function() { return invoices.find({by: this.userId}); });将工作得很好,同时Meteor.publish('invoices', () => { return invoices.find({by: this.userId}); });将返回一个空光标,因为this将没有userId属性.这是因为箭头功能不绑定自己的this,arguments,super,或new.target.
如果它绝对不是(2),那么当您Meteor.userId()在客户端上进行方法调用之前立即记录时会发生什么?
| 归档时间: |
|
| 查看次数: |
4309 次 |
| 最近记录: |