0
我想可以訪問我的ApplicationController中(應用程序需要規範)需要一個控制器加載之前,該資源已通過其各自的航線裝載後然而PracticeController僅適用 - 訪問。 如何確保PracticeController及其內容/模型始終可用? 具體而言,我需要我的flashcardArray在整個應用程序中始終可用,即使練習路線尚未訪問,因此尚未加載。 感謝您的幫助!使提供給ApplicationController中一個控制器模型,可以在灰燼
這裏是我的代碼:
App.Router.map(function() {
this.resource('signup');
this.resource('login');
this.resource('profile');
this.resource('practice');
this.resource('overview');
});
App.ApplicationRoute = Ember.Route.extend({
model: function() {
return this.store.find('user');
}
});
App.LoginRoute = Ember.Route.extend({
controllerName: 'application',
model: function() {}
});
App.PracticeRoute = Ember.Route.extend({
model: function() {
return this.store.find('flashcards');
}
});
//ApplicationController
App.ApplicationController = Ember.ObjectController.extend({
needs: ['practice'],
flashcardArray: Ember.computed.alias('controllers.practice.flashcardArray'),
currentUser: Ember.computed.alias('model'),
isLoggedIn: false
}
});
//PracticeController
App.PracticeController = Ember.ObjectController.extend({
needs: ['application'],
flashcardArray: Ember.computed.alias('model'),
currentUser: Ember.computed.alias('controllers.application.currentUser')
}
});
// Practice template feeded into an outlet of the application template
<script type="text/x-handlebars" id="practice">
<div class="content-padded">
{{#each object in flashcardArray}}
<div class="card_wrapper">
<p><h1>{{{object.num_reference}}}</h1><p>
<p>PinYin: {{{object.mandarin}}}</p>
<p>def: {{object.definition}}</p>
{{/each}}
</div>
</script>
嗨,爲你的答案steve thanx,我想到了這一點,但我認爲可能有一個更清潔的解決方案,因爲用戶應該由一個ObjectController和一個ArrayController的flashcards處理。我不太確定,也許這完全沒有問題。你怎麼看? Tnx再次。 – sunchild 2014-10-12 16:24:43