观察员在Ember不工作? [英] Observer not working in Ember?

查看:76
本文介绍了观察员在Ember不工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

  App.selectedPersonController = Ember.Object.create({
person:null,
personDidChange:function(){
//当人员更改
console.log(PERSON CHANGED)
} .observes('person')
}时, ;

即使'person'属性正在更新,没有任何事情发生。有什么建议么?

解决方案

这是因为,在版本pre4之前,您无法在 em。*。create()函数。您必须首先使用 .extend()函数,并设置所有属性和可观察值,然后创建该对象。



举例来说,请查看正在使用的 jsfiddle 扩展功能。然后尝试使用创建将其删除,您将看到该应用不再有效。


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')
});

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

解决方案

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.

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.

这篇关于观察员在Ember不工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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