我有以下ko标记,它们是两个带有复选框的嵌套ol
<label><input type="checkbox" data-bind="checkedValue:true, checked: selectAll" />Check all</label>
<ol data-bind="foreach: Itemsnum">
<li>
<li><label><input type="checkbox" data-bind="checkedValue:true, checked: selectedOptionnum" />
<span data-bind="text: Name"></span></label></li>
<ol style="margin-left:10px" data-bind="foreach: $parent.Itemsabc">
<li style="margin-left:10px"><label><input type="checkbox" data-bind="checkedValue:true,checked: selectedOptionabc"/>
<span data-bind="text: Name"></span></label></li>
</ol>
</li>
</ol>
这是我的模特
var viewModel = new
function() {
var self = this;
self.Itemsnum = [
{ Name: 'Option 1',
Value: 'o1'},
{ Name: 'Option 2',
Value: 'o2'},
{
Name: 'Option 3',
Value: 'o3'},
{
Name: 'Option 4',
Value: 'o4'}
];
self.Itemsabc = [
{ Name: 'Option a',
Value: 'oa'},
{ Name: 'Option b',
Value: 'ob'},
{
Name: 'Option c',
Value: 'oc'},
{
Name: 'Option d',
Value: 'od'}
];
self.selectedOptionnum = ko.observable(false);
self.selectedOptionabc = ko.observable(false);
self.selectAll = ko.observable();
/* self.selectAll = ko.computed({
read: function() {
var firstUnchecked = ko.utils.arrayFirst(self.Itemsnum, function(item) {
return item.selectedOptionnum() == false;
});
return firstUnchecked == null;
},
write: function(value) {
ko.utils.arrayForEach(self.Itemsnum, function(item) {
item.selectedOptionnum(value);
});
}
});*/
};
ko.applyBindings(viewModel);
我尝试调整以下示例http://jsfiddle.net/romanych/aGFmQ/并在父项之间传播已检查的行为但我收到错误。我想要检查所有cheked盒子,当选中所有单击时,选项[number]所有相关选项[abc]。 有人有线索吗?感谢