How can we observe changes to an array in Ember? I have ember component that uses raw object data from a model, but to demonstrate the issue I am using array property within component itself like:
init:function(){
this._super();
var arr = Ember.A([
Ember.Object.create({"shelfNo": 1, "noOfItems": 2}),
Ember.Object.create({"shelfNo": 2, "noOfItems": 3}),
Ember.Object.create({"shelfNo": 3, "noOfItems": 2})]
);
this.set("someArray",arr);
//DOES NOT WORK
this.get('someArray').addArrayObserver(function () {
Ember.ObjectController.create({
arrayWillChange: function (observedObj, start, removeCount, addCount) {
console.log("in arrayWillChange");
},
arrayDidChange: function (array, start, removeCount, addCount) {
console.log("in arrayDidChange");
}
});
});
}
I also tried :
testObserver: function(){
//DOES NOT WORK
console.log("here");
}.observes('someArray@each')
But both didn't work for me!
Here is a jsbin : http://jsbin.com/EkumOjA/1/
Thanks, Dee