How can an observer find out the before and after values of the observed property in Ember.js?

后端 未结 4 708
梦谈多话
梦谈多话 2020-12-03 10:32

Please see the solution to another question provided by ud3323: http://jsfiddle.net/ud3323/ykL69/. This solution highlights the changed value using the red color. I have an

4条回答
  •  心在旅途
    2020-12-03 11:02

    Take a look at beforeObservers. A beforeObserver fires before a property changes. So if you get the property in a beforeObserver, you will have the the pre-change value. You set up this type of observer using Ember.addBeforeObserver or via the observesBefore function prototype extension.

    That would give you what you need to achieve your goal. I've created the following JSBin based on your fiddle to demonstrate this here: http://emberjs.jsbin.com/qewudu/2/edit

    UPDATED on 2014-10-07 to reflect behavior in Ember 1.7.x.

    UPDATE on 2015-02: beforeObserver has been deprecated. See other answers to this question.

提交回复
热议问题