当项目不可观察时刷新observableArray [英] Refresh observableArray when items are not observables
问题描述
基本上,我有一个observableArray,每个项目的值都不是可观察的.这意味着当我更改项目值时,observableArray的foreach循环中的UI不会相应更新.
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.
如果我必须将它们设置为可观察的,这意味着巨大的变化,那么有没有办法我可以手动刷新UI或observableArray foreach?
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?
推荐答案
是的,您可以为数组调用valueHasMutated
函数:
Yes, you can call valueHasMutated
function for your array:
yourArray.valueHasMutated();
如果首先没有帮助,则可以执行脏"刷新:
If first didn't help you can do 'dirty' refresh:
self.refresh = function(){
var data = self.array().slice(0);
self.array([]);
self.array(data);
};
这里正在演奏小提琴: http://jsfiddle.net/vyshniakov/FuEy6/2/
Here is working fiddle: http://jsfiddle.net/vyshniakov/FuEy6/2/
这篇关于当项目不可观察时刷新observableArray的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!