要訪問從另一個控制器屬性首先需要包括通過needs
像這樣:
App.ModalImportController = Ember.ArrayController.extend({
needs: "team",
teamController: Ember.computed.alias("controllers.team"),
});
,那麼你將有機會獲得它,像這樣的屬性:
// still in ModalImportController
syncAccount: function() {
return this.get('teamController.syncAccount');
}.property('teamController.syncAccount')
我現在還沒有對它進行測試,但這是我在稍微不同的設置中完成的。
來源: [http://guides.emberjs.com/v1.13.0/controllers/dependencies-between-controllers/][1]
對於toggeling送我用的更新請求:
syncAccount: Ember.computed('model.syncAccount', {
get: function() {
return this.get('model.syncAccount');
},
set: function(key, value) {
this.set('model.syncAccount', value);
// do all you need to do via AJAX here
return value;
}
})
紙條,那你也可以得到從這裏的價值,所以改變你的輸入幫手:
{{input type="checkbox" name="syncAccount" value=syncAccount }}
我沒有團隊控制員。相反,在應用程序控制器中,我有一個名爲currentTeam的助手。我使用你的建議來訪問像這樣的值:'syncAccount:function(){this.get('applicationController.currentTeam.syncAccount'); } .property('currentTeam.syncAccount')'syncAccount的值似乎沒有得到最初的查詢。從開發工具中,如果我調用$ E.syncAccount,它會返回:function()App.ModalsController.Ember.ObjectController.extend.syncAccount()切換複選框後,調用$ E.syncAccount返回'true'。如何在打開前設置此值? – Jim
看起來好像是輸入助手有問題: value = syncAccount不起作用,但value =「syncAccount」將複選框標記爲首次打開時選中。切換仍然不起作用(即,單擊複選框不會在檢查/不檢查之間切換。是否碰巧知道這是我必須在控制器中處理的行爲(即不是默認值?) – Jim