0
Нокауты, начинающие делать ставки. Не удается получить доступ к функции "RemoveItem"Нокаутирующие обязательные родители
Html
<div>
<div data-bind="with: idea">
<input type = "text"
data-bind = 'value:itemToAdd' />
<input type="button" data-bind="click:$parent.addItem" value="add" />
<ul data-bind = "foreach:allItems">
<li>
<span data-bind = "text:$data"></span>
<input type="button" data-bind="click: $parents[1].removeItem" value="remove"/>
</li>
</ul>
</div>
</div>
Script
var vm = {
idea: ko.observable({
allItems: ko.observableArray(),
itemToAdd : ko.observable("")
}),
addItem : function() {
var item = this.itemToAdd();
this.allItems.push(item);
this.itemToAdd("");
},
removeItem : function (data) {
this.allItems.remove(data);
}
};
ko.applyBindings(vm);
jsFiddle here бы признателен за любую помощь. Спасибо!
Еще раз спасибо, Артем! –