Knockout observableArray not updating

后端 未结 1 1516
无人共我
无人共我 2020-12-21 15:43

I have an observableArray that won\'t update in the HTML even though I can log it to the console and see it change. I wish jsfiddle had a console so I could show that part.<

相关标签:
1条回答
  • 2020-12-21 16:24

    You have an unnecessary set of parenthesis in

    self.searchResult().push(self.people()[pKey]); 
    

    it should be

    self.searchResult.push(self.people()[pKey]);
    

    Demo JSFiddle.

    Because when you write self.searchResult() you are accessing the underlaying array in the observable. And when you push into that array KO won't be notified about the changes so you need to use the push method on the observableArray itself.

    By the way Knockout has a great set of useful array helpers which could simplify your filtering logic.

    0 讨论(0)
提交回复
热议问题