5

私はMeteorが初めてなので、遊んでいて、今はこの問題に悩まされています。

React Router を使用して、URL /(:userId) に基づいてテーマを表示しようとしています。URL に userId が挿入されていない場合は現在のユーザーのテーマが表示され、現在のユーザーが存在しない場合はデフォルトのテーマが表示されます。

ランダムに動作しています。正しいテーマを取得することもあれば、データが存在する場合でも、themeColor を読み取るときに undefined がスローされることもあります。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()
    }

},
4

1 に答える 1