7

Meteor の Leaderboard の例を試していますが、プレイヤーのスコアをランダム化しようとするとバグが発生します。

私がヒットしている例外はException while simulating the effect of invoking '/players/update' undefined

関連するコードは次のようになります。

'click input.randomize_scores': function () {
  Players.find().forEach(function (player) {
    random_score = Math.floor(Math.random()*10)*5;
    Players.update(player, {$set: {score: random_score}})
  });
}

Leaderboard.js の完全なコンテンツはこちら

ここでかなりばかげたことをしているような気がします。ポインタをいただければ幸いです。

4

1 に答える 1

15

update()の最初の引数は、ドキュメントIDまたは完全なMongoセレクターである必要があります。完全なプレーヤードキュメントを渡します。これを試して:

Players.update(player._id, {$set: {score: random_score}});

これは略記です:

Players.update({_id: player._id}, {$set: {score: random_score}});
于 2012-04-11T06:12:37.033 に答える