DalekSupreme
DalekSupreme

Reputation: 1513

How can I change a ko.observabel with durandal from another view?

So basically what I want to do is this:

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>

It calls the function and adds it to the list but at the main.html nothing changes. why?

Upvotes: 1

Views: 54

Answers (1)

zewa666
zewa666

Reputation: 2603

The problem is because you add the new stuff to the result of the observableArray, not the observableArray itself. When you want to update the underlying ko.observableArray you have to do

self.selectedlist.push('Whatever')

For info regarding manipulating knockout arrays take a look at their documentation

Upvotes: 2

Related Questions