问题
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