【发布时间】:2013-12-09 18:40:43
【问题描述】:
我们如何在 Ember 中观察数组的变化?我有使用来自模型的原始对象数据的 ember 组件,但为了演示我在组件本身中使用数组属性的问题,例如:
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");
}
});
});
}
我也试过了:
testObserver: function(){
//DOES NOT WORK
console.log("here");
}.observes('someArray@each')
但两者都不适合我!
这是一个 jsbin:http://jsbin.com/EkumOjA/1/
谢谢, 深
【问题讨论】:
标签: javascript ember.js