私はangularjsを使い慣れていませんし、単純なタスクであるように思えますし、誰かが私を助けてくれることを願っていました。私のコントローラには次のコードがあります。私は$ scope.optionsに追加する必要があるデータを動的に生成しています。
これは私のデータは次のようになります。この作品[{ name: "a", id: 1 }, { name: "b", id: 2 }];
:
$scope.options = [{ name: "a", id: 1 }, { name: "b", id: 2 }];
これは動作しません:
var res = [{ name: "a", id: 1 }, { name: "b", id: 2 }];
$scope.options = res;
はコントローラー:
for (var i = 0; i < jsonArray.length; i++) {
if(i == (numberofitems-1)){
teststuff += "{name:\""+jsonArray[i]["pondpitname"]+"\", id:"+jsonArray[i]["id"]+"}";
}
else
{
teststuff += "{name:\""+jsonArray[i]["pondpitname"]+"\", id:"+jsonArray[i]["id"]+"}, ";
}
}
// teststuff looks like this [{ name: "a", id: 1 }, { name: "b", id: 2 }];
var res = "["+teststuff+"]";
$scope.options = res;
あなたはそれを "動作しない" 対 "作品" とはどういう意味ですか? –
文字列を使用してこの配列を構築する特別な理由はありますか? – horyd
**あなたの** res **変数は配列ではなく文字列であると思われます。それはおそらく動作しません。 – maddob