0

文字列score20130901を mongodb の変数 ( flag.currentflag ) に置き換えたい:

var selected_book = Books.findOne({_id: book});  // works
var flag = Flags.findOne({_id: "bookflag"});  // flag.currentflag works
var tmpone = Flags.findOne({_id: "one"}); // works

if (selected_book.score20130901[tmpone.oneround] > 0)

すべての変数を alert(...); でテストしました。そして、各変数から正しい値を取得します。しかし、score20130901 を flag.currentflag に置き換えると、機能しません。

エラー: Uncaught TypeError: 未定義のプロパティ '0' を読み取れません

4

1 に答える 1

1

表記object.propertyは に相当しobject["property"]ます。

したがって、 を使用できますselected_book[flag.currentflag]。これは と同じ結果になりselected_book.score20130901ます。

于 2013-08-29T12:42:57.283 に答える