观察者如何发现ember.js 1.x中观察到的属性的前后值? [英] How can an observer find out the before and after values of a observed property in ember.js 1.x?

查看:116
本文介绍了观察者如何发现ember.js 1.x中观察到的属性的前后值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道的是如何做到这一点如何观察者在Ember.js?
中找到所观察到的属性的前后值与最后一个版本的Ember.JS。



现在beforeObserver和观察者只发送'this'(正在观看的对象)和查询。 这里和示例。

  fooWillChange:function(){
console.log(
arguments.length,// 2
arguments [0] == this,// true
arguments [1] =='foo'// true
);
} .observesBefore('foo'),

fooDidChange:function(){
//等于fooWillChange
} .observes('foo')

在foo中我可以用获取,但是在一个数组内观看一个属性的情况下(如 bar。@ each.name )这将无法正常工作。

$ b $



我已经创建了一个jsbin作为示例



有关更多信息,请访问链接。


What I want to know is how to do this How can an observer find out the before and after values of the observed property in Ember.js? with the last version of Ember.JS.

Now beforeObserver and observer send only 'this'(the object that is watching) and the the query. Here and example.

fooWillChange: function() {
    console.log(
      arguments.length, //2
      arguments[0] == this, //true
      arguments[1] == 'foo' //true
    );
}.observesBefore('foo'),

fooDidChange: function() {
    //exactly equal fooWillChange
}.observes('foo')

in 'foo' case I can just pick the value with get but in the case of watching a property inside of an array(like bar.@each.name) this won't work.

解决方案

For observing array changes you can use the function addArrayObserver and then override the two functions willChange and didChange to read the changes.

I have created a jsbin as an example

For more information visit this link.

这篇关于观察者如何发现ember.js 1.x中观察到的属性的前后值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆