观察员在Ember不工作? [英] Observer not working in Ember?
问题描述
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屋!