我有 html 作为: JSfiddle
<ul data-bind="foreach: Items">
<li data-bind="click: setTextColor, text: 'Color: ' + color"></li>
<ul data-bind="foreach:add">
<li data-bind="text:test"></li>
</ul>
</ul>
和JS如下:
var Item = function(color) {
var self = this;
self.color = String(color);
self.setTextColor = function(item, event) {
console.log(item.color);
$(event.target).css('color', color);
};
},
add = function (test){
this.test = String (test);
};
ko.applyBindings(new function() {
this.Items = ko.observableArray([
{new Item('red'),ko.observableArray(new add('colore'),new add('is'),new add('red'))},
{new Item('blue'),ko.observableArray(new add('colore'),new add('is'),new add('blue'))},
{new Item('green'), ko.observableArray(new add('colore'),new add('is'),new add('green'))}
]);
}());
但它没有填充数据。谁能告诉我是什么问题!!!