Detect if a change occur in observableArray

狂风中的少年 提交于 2020-01-05 07:11:09

问题


Does anyone have idea, if it's possible to detect whenever a change occur inside observableArray while using ko mapping, this mean without having to create the model by hand?

self.items = ko.observableArray([])
var data = ko.mapping.fromJS(result)
self.items.push(data);

I would like to log any changes occurred in any property inside my array of objects.

Thanks


回答1:


If I'm not mistaken, you should be able to use subscribe on the observable to get that information.

See the bottom of this page for more info:

Explicitly subscribing to observables




回答2:


self.items = ko.observableArray([])   
self.item.subscribe(function(context){  
//Comment if there is any changes in the observable array this function will get trigger and changed date ma get in context   

});


来源:https://stackoverflow.com/questions/12076886/detect-if-a-change-occur-in-observablearray

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!