5

我是 Meteor 的新手,所以我一直在玩,现在我遇到了这个问题。

我正在使用 React Router 尝试显示基于 URL /(:userId) 的主题。如果 URL 中没有插入 userId,则应显示当前用户的主题,如果没有当前用户,则应显示默认主题。

它在随机工作。有时我得到正确的主题,有时在读取 themeColor 时它会抛出 undefined 即使数据在那里。我可以通过 console.log 看到它总是得到正确的 ID,但 findOne 仍然可以抛出未定义的。当我更改 URL (/xyz) 并返回到默认 URL (/) 时,它会特别发生。

我通过控制台验证了 userId 是 themeColor 和 themeTextColor 的实际所有者。

我正在使用 React、React-router、自动发布。我删除了不安全的。

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()
    }

},
4

1 回答 1

0

由于代码有时可以工作。可能有一些与架构不匹配的测试数据。所以测试集合中的所有数据。

于 2016-04-16T04:49:53.327 回答