我有一个Ember.Mixin
它观察到它的属性之一(这里bar.baz
).
我扩展了这个 Mixin 并设置了bar.baz
in the .create()
参数,但我的观察者没有被调用。
这是我的代码:
App.FooMixin = Ember.Mixin.create({
barBazDidChange: function() {
console.log('barBazDidChange'); // never called
}.observes("bar.baz")
});
App.Foo = Ember.Object.extend(App.FooMixin);
App.fooObject = App.Foo.create({
bar: Ember.Object.create({
baz: "ember"
})
});
以及相关的 jsfiddle :http://jsfiddle.net/aMQmn/ http://jsfiddle.net/aMQmn/
我当然可以打电话给观察者init()
方法如下,但我想知道是否有更好的解决方案(或者这个解决方案是否是正确的方法):
App.FooMixin = Ember.Mixin.create({
init: function() {
this._super();
if (this.getPath('bar.baz')) {
this.notifyPropertyChange('bar.baz');
}
}
});
所以 7 天内没有答案...我会做的不是在创建时传递属性而是更改创建并设置属性,如下所示:
App.fooObject = App.Foo.create().set('bar', Ember.Object.create({baz: "ember"}));
如果还不够满意,也许你可以在 github 上的 ember 项目中发布一个问题:https://github.com/emberjs/ember.js/issues https://github.com/emberjs/ember.js/issues
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)