App = Ember.Application.create({
currentProject: 21
});
默认值为 21,当 App.currentProject
我点击 {{#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}},我不知道如何设置动作。
版本信息
- 要求:2.1.4
- jQuery:v1.9.1
- 余烬:v1.0.0-rc.1
- 车把:1.0.0-rc.3