App = Ember.Application.create({
currentProject: 21
});
App.currentProject
默认值为21,当我点击{{#linkTo}}时,我想在:project_id
中设置App.currentProject
。
路线:
App.Router.map(function() {
this.resource('project', { path: '/project/:project_id' }, function(){
this.resource('tasks', function(){
this.route('new');
});
})
});
App.TasksRoute = Ember.Route.extend({
model: function(params){
return App.Project.find(params.project_id);
},
setupController: function(controller, model) {
controller.set('content', model.tasks);
}
})
模板:
{{#each controller}}
<div class="panel">
{{#linkTo 'tasks' this}} //click this linkTo, render to project/:project_id/tasks URL and set the App.currentProject to the :project_id at the sametime
<div class="top"><i class="batch-big b-code"></i>
<h6>{{title}}</h6>
</div>
{{/linkTo}}
</div>
{{else}}
<div>There are no Projects.</div>
{{/each}}
我不知道路线中App.currentProject
设置为project_id
的位置:
App.TasksRoute = Ember.Route.extend({
model: function(params){
App.set('currentProject', params.project_id); //I add the code to here,but it did not work
return App.Project.find(params.project_id);
},
setupController: function(controller, model) {
controller.set('content', model.tasks);
}
})
模板{{#linkTo}},我不知道如何设置操作。
版本信息