Refresh observableArray when items are not observables

前端 未结 5 1213
孤街浪徒
孤街浪徒 2020-12-01 15:58

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 observable

5条回答
  •  伪装坚强ぢ
    2020-12-01 16:24

    I ended up using the dirty approach from above but made it so that all my observable arrays had this functionality.

    ko.observableArray.fn.refresh = function () {
            var data = this().slice(0);
            this([]);
            this(data);
        };
    

    The valueHasMutated didn't work for me. Its kind of lame the entire list has to be updated. Or in my case find a way to extend the ko mapping plugin to fill the observable arrays with observable objects..

提交回复
热议问题