当我单击{{#linkTo}}并在ember.js中设置对象时

时间:2013-04-18 14:23:59

标签: view model controller ember.js action

 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}},我不知道如何设置操作。

版本信息

  • 要求:2.1.4
  • jQuery:v1.9.1
  • Ember:v1.0.0-rc.1
  • 把手:1.0.0-rc.3

0 个答案:

没有答案