I need to figure out which element was removed from my Knockout observableArray. Please see my jsFiddle.
I can subscribe to the change, but it only returns value, which is the current array after the add or remove.
self.selectedDataPointOptions.subscribe(function(value) {
// how can I see which one was added or removed?
alert(value);
});
Knockout includes
ko.utils.compareArrayswhich you can use to compare one array to another. Here’s a helper function that notifies for each added or removed item in the array:Here it is in action: http://jsfiddle.net/mbest/Jq3ru/
Beginning with Knockout 3.0, you can use the
arrayChangeevent to do this more easily. More info is here: http://blog.stevensanderson.com/2013/10/08/knockout-3-0-release-candidate-available/