Ember.js: Observing all object properties

前端 未结 2 498
-上瘾入骨i
-上瘾入骨i 2021-01-11 22:00

I would like to observe all changes on an object properties.
In the following example, i would like to be notified by the personChanged observer if firstname or lastname

2条回答
  •  孤城傲影
    2021-01-11 22:49

    What you have there is right using inline observers, but you just have some syntax errors. However it is even simpler to do with the key word observes. So I have tweaked your example a little below.

    App.MyObject: Ember.Object.create({
        firstname: 'first',
        lastname: 'last',
        personChanged: function() {
            //firstname or lastname changed
        }.observes('firstname','lastname')
    });
    

    Note: I put quotes around the properties

    Source: http://emberjs.com/guides/object-model/observers/

提交回复
热议问题