我有一个类似这样的淘汰赛 js 模型:
var Model = function(model)
{
var self = root = this;
self.ObjectA = new ObjectA(model.ObjA);
self.includeImage = function(image){
self.ObjectA.Images.push(image);
}
}
var ObjectA = function(objA){
var self = this;
self.Images = ko.observableArray();
self.ObjectB = ko.observableArray(ko.utils.arrayMap(objA.ObjectsB, function(ob){
return new ObjectB(ob);
}));
}
var ObjectB = function(objB){
var self = this;
self.ObjectC = new ObjectC(objB.objC);
}
var ObjectC = function(objC){
var self = this;
self.ImagesC = ko.utils.arrayMap(objC.ImagesC, function(img){
return new Image(img);
});
}
var Image = function(image){
var self = this;
self.Key = image.Key;
self.Value = image.Value;
self.Url = image.Url;
}
然后,我在桌子上有这个 HTML:
<tbody data-bind="foreach: ObjectA.ObjectB">
<tr>
<td>
<!-- ko if: ObjectC.Images.length > 0 -->
<div>
<img data-bind="attr: { src: ObjectC.Images[0].Url }" />
<button data-bind="click: root.includeImage">include</button>
</div>
<div data-bind="foreach: ObjectC.Images">
<!-- ko if: $index() !== 0 -->
<div>
<img data-bind="attr: { src: Url }" />
<button data-bind="click: root.includeImage">include</button>
</div>
<!-- /ko -->
</div>
<!-- /ko -->
</td>
</tr>
</tbody>
我遇到的问题是函数includeImage,我收到的参数不是ObjectC的图像..参数的类型是ObjectB..为什么会这样?它的一些foreach坏了?