灰烬中的观察者功能? [英] Observer functionality in Ember?

查看:71
本文介绍了灰烬中的观察者功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法让观察者在Ember.js中实际执行任何操作。基本上,我有一个Ember.Select下拉菜单,并且希望将更多操作绑定到在下拉列表中选择值的事件。例如:

I can't get an observer to actually do anything in Ember.js. Basically, I have a Ember.Select dropdown menu, and want to bind some more action to the event of selecting the value in the dropdown. For example:

App.selectedPersonController = Ember.Object.create({
  person: null,
  personDidChange: function() {
    // do something here when the person changes
    console.log("PERSON CHANGED")
  }.observes('person')
});

即使'person'属性正在更新,也没有任何反应。有什么建议么?

And nothing is happening, even though the 'person' attribute is getting updated. Any suggestions?

推荐答案

这是因为从版本4开始,您无法在 Em。*。create()函数。首先必须先使用 .extend()函数,并在其中设置所有属性和可观察对象,然后创建该对象。

This is due to the fact that as of version pre4 you cannot set a property or observable upon the Em.*.create() function. You have to first use the .extend() function first and set all your properties and observables in that, then create that object.

作为示例,请看下面的 jsfiddle 扩展功能。然后尝试仅使用 create 将其取消,您将看到该应用程序不再起作用。

As an example, take a look at this jsfiddle that is working with the extend functionality. Then try to take it away by using only create and you'll see that the app no longer works.

这篇关于灰烬中的观察者功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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