Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Refresh observableArray when items are not observables

Tags:

knockout.js

Basically I have an observableArray and the values for each item are not an observable. This means when I change an item value the UI within a foreach loop of the observableArray does not update accordingly.

It means a massive change if I have to set them to observable, so is there a way I can refresh either the UI or observableArray foreach manually?

like image 686
user1166905 Avatar asked Nov 05 '12 12:11

user1166905


1 Answers

Yes, you can call valueHasMutated function for your array:

yourArray.valueHasMutated(); 

EDIT: If first didn't help you can do 'dirty' refresh:

self.refresh = function(){     var data = self.array().slice(0);     self.array([]);     self.array(data); }; 

Here is working fiddle: http://jsfiddle.net/vyshniakov/FuEy6/2/

like image 108
Artem Vyshniakov Avatar answered Sep 25 '22 04:09

Artem Vyshniakov