How can I observe array changes and see which new item is added?

onArrayChanged: function(obj, keyName, value) {

    // What is value here, exactly?

}.property('array.@each')

When an element is added to the array, how do you know which value was added? LIkewise, when a value is removed from an array, how do I access this?

+5
source share
1 answer

Take a look at addArrayObserver , see http://jsfiddle.net/pangratz666/EE65Z/ :

var a = Ember.A('a b c d e f g'.w());

var o = Ember.Object.create({
    arrayWillChange: Ember.K,
    arrayDidChange: function(array, start, removeCount, addCount) {
        console.log(arguments);
    }
});

a.addArrayObserver(o);
+12
source

All Articles