我有一个foreach淘汰赛循环,我想在其中将每个创建的复选框的ID设置为循环中我可观察的名称。
<tbody data-bind="foreach: FormatVendorRules">
<tr class="h4">
<td data-bind="text: SubCategoryCode"></td>
<td>
<div class="onoffswitch">
<input name="validationCheckBox" type="checkbox"
name="onoffswitch" class="onoffswitch-checkbox"
id="myId+"text: SubCategoryCode"" data-bind="checked: IsEnabled" /> //This is where I want to define the id
<label class="onoffswitch-label" for="myId+"text: SubCategoryCode"">
<div class="onoffswitch-inner"></div>
<div class="onoffswitch-switch"></div>
</label>
</div>
</td>
</tr>
</tbody>
所以编号应该是
您需要使用attr绑定来设置id属性(或其他任何属性):
data-bind="checked: IsEnabled, attr: { id: 'myId' + SubCategoryCode() }"
注意:如果此属性是ko.observable ()
,SubCategoryCode()
则仅需在末尾添加。但是,如果您SubCategoryCode
是常规属性,则只需编写以下内容:attr: { id: 'myId' + SubCategoryCode }
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句