Meteor.subscribe回调函数,保存到会话,但返回未定义的
我在/client中有这个profile.js文件/Meteor.subscribe回调函数,保存到会话,但返回未定义的,meteor,publish-subscribe,reactive-programming,Meteor,Publish Subscribe,Reactive Programming,我在/client中有这个profile.js文件/ /*::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: ✚ subscribe :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/ var currentUser, currentU
/*:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
✚ subscribe
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/
var currentUser, currentUserInterests
Meteor.subscribe("tikiUser", function(){
Session.set("currentTikiUser", tikiUser.find({}).fetch())
})
/*:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
✚ helpers
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/
Template.profileTags.helpers({
isActive:function(){
currentUser = Session.get("currentTikiUser")
currentUserInterests = currentUser.userInterests
console.log(currentUserInterests)
}
})
我试图获取currentUser.userInterests中的值(在我的助手中),但它总是返回“undefined”。但是,如果我在助手中输入console.log(currentUser),我将获得正确的对象,但这只是第一次。第二次(当我刷新页面时)我得到以下示例:
- 模板帮助程序中出现异常:.isActive
thx,Cursor是一个反应源,您不需要存储在另一个反应源(会话)中,您可以编写
tikiUser.find({}).fetch()
无论您想在哪里,它都是一个反应源,您也是吗出版物没有更改?您好,您的建议不起作用,现在我总是有未定义的问题。你能在Meteopad.com上用最少的代码重现这个问题吗