How to observe all object property changes?

前端 未结 3 520
迷失自我
迷失自我 2020-12-03 22:55

For arrays I know you can do something like this:

function() {
}.observes(\"array.@each\")

What I did was convert the object into an array

3条回答
  •  孤街浪徒
    2020-12-03 23:44

    You can get a list of properties in an object and apply them to a new property:

    attrs = Ember.keys(observedObject);
    var c = Ember.computed(function() {
        // Do stuff when something changes
    })
    Ember.defineProperty(target, propertyName, c.property.apply(c, attrs));
    

    Here is a working jsbin. Creating an observer instead of a property should be possible using a similar approach.

提交回复
热议问题