ダイナミックラジオボタングループを生成しようとして、name属性でグループ化する際に問題が発生しています。 KOは次の形式を使用して名前を生成しています: "ko_unique_ {0}"と設定しているバインディングを使用していません。ラジオバインディングの複数のグループ(別名:name属性)のKnockoutjsサポート
これを解決する方法はありますか?
多くの感謝!
vm = {
questions: [{ id: "q1", question: "first question", answer: "y" },
{ id: "q2", question: "second question", answer: "n" }],
answerOptions: [{ key: "y", value: "Yes" },
{ key: "n", value: "No"}]
};
と次のマークアップ:
<ol data-bind="foreach: questions">
<li>
<span data-bind="text: question"></span>
<span data-bind="foreach: $parent.answerOptions">
<span data-bind="text: value"></span><input type="radio" data-bind="value: key, name: $parent.id, checked: $parent.answer" />
</span>
</li>
</ol>
これは電流出力(名前はko_unique_1、ko_unique_2、ko_unique_3と属性、代わりにQ1のko_unique_4値、Q1で次のvmを考えると
、q2、q2):
<ol data-bind="foreach: questions">
<li>
<span data-bind="text: question">first question</span>
<span data-bind="foreach: $parent.answerOptions">
<span data-bind="text: value">Yes</span><input type="radio" data-bind="value: key, name: $parent.id, checked: $parent.answer" name="ko_unique_1" value="y">
<span data-bind="text: value">No</span><input type="radio" data-bind="value: key, name: $parent.id, checked: $parent.answer" name="ko_unique_2" value="n">
</span>
</li>
<li>
<span data-bind="text: question">second question</span>
<span data-bind="foreach: $parent.answerOptions">
<span data-bind="text: value">Yes</span><input type="radio" data-bind="value: key, name: $parent.id, checked: $parent.answer" name="ko_unique_3" value="y">
<span data-bind="text: value">No</span><input type="radio" data-bind="value: key, name: $parent.id, checked: $parent.answer" name="ko_unique_4" value="n">
</span>
</li>
</ol>
まさに私のquestinでで行うことができますが、私はまた、jQueryの検証プラグインでノックアウトを使用してトラブルを抱えています。このplugingは名前に依存しているからです。ありがとう。 –