findOne 抛出未定义,即使数据在那里
findOne throwing undefined even though the data is there
我是流星的新手,所以我一直在玩,现在我遇到了这个问题。
我正在使用 React Router 尝试显示基于 URL/(:userId) 的主题。如果没有在 URL 中插入 userId,则应显示当前用户的主题,如果没有当前用户,则应显示默认主题。
它是随机工作的。有时我得到正确的主题,有时它在读取主题颜色时抛出未定义,即使数据在那里。我可以看到控制台.log它总是得到正确的 Id,但仍然发现一个可以抛出未定义。当我更改 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()
}
},
由于代码在某个时候起作用。可能存在一些与架构不匹配的测试数据。因此,请测试集合中的所有数据。
相关文章:
- 如何使该数据在所有元素中加载
- 数据-在IE8中不起作用
- 如何以特定格式存储数据?在WYSWYG中
- 如何确保在AngularJS中,数据在使用之前先加载
- 如何使用D3.js根据json中给出的数据在Heatmap中创建可变大小的矩形
- 当使用“”时,事件数据在jquery中返回空对象;on()”;
- 为什么我发布的数据在这个AJAX调用的Controller目标中为null
- 如何通过单击数据在新窗口上显示TableView数据
- dataTransfer.set拖放的数据在chrome中不起作用
- ExtJs 4 GridPanel with CellEdit:输入的数据在验证失败时丢失
- 发送数据在接收时更改
- 使用 POST 方法通过 ajax 发送的数据在发送到服务器之前是否必须进行 URL 编码
- PouchDB数据在销毁后未删除
- flow.js上传的文件数据在哪里
- 数据在确认框中的显示方式存在问题
- 如何使用jsonp调用返回的数据在Durandal中呈现视图
- 数据在发送前重置
- findOne 抛出未定义,即使数据在那里
- Angular返回一个空页面,即使所有数据都在那里
- 流星-不填充{{each}},即使控制台说数据在那里