3438 次
2 に答える
4
バインディングは、生成された要素の属性optionsValue
を設定するために使用されるプロパティを決定するために使用されます。value
option
この1行の変更により、サンプルが機能します。
self.selectedAccount = ko.observable(1);
バインディングvalue
は ID に設定されselectedAccount
ており、生成されたoptions
要素の値は実際には ID です。
于 2012-08-29T21:25:29.453 に答える
0
「値」をオプションのリストにあるものの1つにする必要があります.....
私はこれを処理するためにいくつかのコーヒースクリプトを書くことになりました....
replaceWithMatchingExt = (observableToFind, observablePropertyToSet, list, match) ->
return if not observablePropertyToSet
return if not observableToFind()
return if list.length == 0
observablePropertyToSet (x for x in list when x[match]() == observableToFind()[match]())[0]
replaceWithMatching = (prop, list, match) ->
replaceWithMatchingExt(prop, prop, list, match)
これにより、(コーヒースクリプトも...)
replaceWithMatching @Product, @Products(), 'Id'
Product が値で、Products が選択肢のリストであると仮定すると、「Id」は一致させたいプロパティです。つまり、Id は、同等の製品を作成するために使用できるものです。
次に、コードは監視可能な Product を Products リスト内のオブジェクトと一致する場合に置き換えます。
于 2012-08-29T21:22:37.543 に答える