我是Meteor的新手所以我一直在玩,现在我已经遇到了这个问题.
我正在使用React Router尝试显示基于URL /(:userId)的主题.如果没有userId插入到URL中,它应该显示当前用户的主题,如果没有当前用户,则应该显示默认主题.
它随机工作.有时我会得到正确的主题,有时候在读取themeColor时会抛出未定义的内容,即使数据存在.我可以通过console.log看到它总是得到正确的ID,但仍然findOne可以抛出undefined.当我更改URL(/ xyz)并返回默认值(/)时,会发生这种情况.
我在控制台验证了userId是themeColor和themeTextColor的实际拥有者.
我正在使用React,React-router,autopublish.我删除了不安全的东西.
getMeteorData() {
var currentViewedPageId = this.props.params.userId? this.props.params.userId:(Meteor.userId()?Meteor.userId():false);
console.log(currentViewedPageId); //Allways right
console.log(Personalization.findOne({owner: currentViewedPageId}).themeColor); //Sometimes undefined, sometimes not
if(currentViewedPageId)
{
return {
currentUser: Meteor.user(),
themeColor: Personalization.findOne({owner: currentViewedPageId}).themeColor,
themeTextColor: Personalization.findOne({owner: currentViewedPageId}).themeTextColor
};
}
return {
currentUser: Meteor.user()
}
},
Run Code Online (Sandbox Code Playgroud)