基本上我想做的就是:
main.html中:
<div style="cursor:pointer" data-bind="compose: {model: $data, view: "child.html"}" />
<div style="background-color:#CCC; cursor:pointer; width:45px; " data-bind="visible: selectedlist ().length > 0">something</div>
main.js:
self.selectedlist = ko.observableArray([]);
self.addfnc = function(){self.selectedlist().add;}
child.html:
<div data-bind="click: addfnc()">ADD</div>
它调用该函数并将其添加到列表中,但在main.html中没有任何更改。为什么呢?
答案 0 :(得分:2)
问题是因为你将新东西添加到observableArray的结果中,而不是observableArray本身。当你想更新底层的ko.observableArray时,你必须做
self.selectedlist.push('Whatever')
有关操纵挖空阵列的信息,请查看their documentation