当项目不是可观察的时刷新 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/
这篇关于当项目不是可观察的时刷新 observableArray的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!