[英]Knockoutjs observable array of objects binding selector by name
I have an observable array of observable objects called FieldsAndValues 我有一个称为FieldsAndValues的可观察对象的可观察数组
I'm binding the values of each object by their index using this 我通过使用此对象的索引绑定每个对象的值
<input type="radio" data-bind="checked: DTO.FieldsAndValues()[0].Value, checkedValue: 'true'" class="separate" name="rdo">Yes
<input type="radio" data-bind="checked: DTO.FieldsAndValues()[0].Value, checkedValue: 'false'" class="separate" name="rdo">No
My question is, is there a way to bind the objects using the LeaveFieldName property as a selector and not their index? 我的问题是,是否有一种方法可以使用LeaveFieldName属性作为选择器而不是其索引来绑定对象?
Isn't it just the case of using foreach binding on that array, and not manually specifying the index of each node? 不仅仅是在该数组上使用foreach绑定,而不是手动指定每个节点的索引的情况?
eg 例如
<div data-bind="foreach: DTO.FieldsAndValues">
<div>
<input type="radio" data-bind="checked: LeaveField.LeaveFieldName, checkedValue: true" class="separate" name="rdo">Yes
<input type="radio" data-bind="checked: LeaveField.LeaveFieldName, checkedValue: false" class="separate" name="rdo">No
</div>
</div>
Plus, even if you bind it, your value will be either true / false, not the IsRegularAndProbiSeparate
(etc.). 另外,即使您绑定它,您的值也将是true / false,而不是
IsRegularAndProbiSeparate
(等等)。 That's what checkedValue binding is for. 这就是checkedValue绑定的用途。 You even stringify boolean which isn't a good idea, should be just
checkedValue: true
您甚至将布尔值字符串化不是一个好主意,应该只
checkedValue: true
Alternatively you could use with binding ( with: LeaveField
) inside the array output and have access to all properties in each recurrence. 另外,您可以用绑定(使用
with: LeaveField
)阵列输出内,并获得在每次复发的所有属性。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.