1
的負載等控制器我下面的代碼有:Ember.js:計算財產,涉及未刷新在模型
App.UserController = App.EditableController.extend({
needs: 'application',
test: function() {
return this.get('controller.application.me.email');
}.property('controller.application.me.email'),
});
App.ApplicationController = Ember.Controller.extend({
isPublic : true,
me : null,
init: function() {
this.set('me', App.User.find(1));
this._super();
}
});
但是計算的特性似乎並不一旦模型加載更新(從控制檯) :
> App.__container__.lookup('controller:Application').get('me.email')
"[email protected]"
> App.__container__.lookup('controller:User').get('test')
undefined
我錯過了什麼嗎?
這樣做的伎倆,非常感謝你! 'EditableController'確實是ObjectController的擴展。爲什麼'contentBinding'工作,但不是'controllerBinding'? –
@BrianGates我很高興我能幫上忙。至於contentBinding這是因爲ObjectController需要定義content屬性,因此我們在這裏使用它,簡單的'Controller'沒有這樣的屬性,所以在這種情況下它也可以是'fooBinding' ,然後'property('foo')' – intuitivepixel
進一步測試後,使用'contentBinding'似乎會破壞現有的'content'屬性(這是有道理的),但是如果我使用任何其他值,我會收到一個錯誤'Assertion失敗:無法將set('foo',)委託給對象代理的'content'屬性:其'content'未定義。'做一點研究,我發現這:http://stackoverflow.com/questions/12502465/bindings-on-objectcontroller-ember-js。所以我所要做的就是聲明一個'controller'屬性,然後我可以使用'controllerBinding'。 –