5
我試圖從DashboardIndexController訪問DashboardIndexView訪問數據
JP.DashboardIndexController = Ember.Controller.extend({
users: []
});
數據是否有可能訪問用戶JP.DashboardIndexView在didInsertElement?
didInsertElement : function(){
console.log(this.get("controller.users").objectAt(0));
}
這是我DashboardIndexRoute:
JP.DashboardIndexRoute = Ember.Route.extend({
setupController: function(controller, model) {
controller.set('users', JP.User.find());
}
});
謝謝
僅編輯
console.log(this.get("controller.users").objectAt(0));
返回數據時,我去UsersIndex
然後回DashboardIndex
..我認爲這是一個問題與初始化,但我不知道,如何解決它。
我無法在'usersChanged'內獲取計算屬性...'this.get('controller')。get('model')。get('length')'顯示我的模型已加載,但'this.get('controller')。get('total')'(計算屬性)返回NaN。有任何想法嗎? – 2013-07-18 13:44:33
也是,每次加載用戶時都會觸發。是否有所有用戶加載時的觸發器?謝謝! – 2013-07-18 13:46:02
我沒有足夠的信息來回答你的第一個問題。對於第二個問題,您可以嘗試使用'Ember.run.once'來安排方法;見https://gist.github.com/teddyzeenny/6029603 – 2013-07-18 14:08:23