Ember:你如何从路由器访问模型?

Ram*_*yag 31 coffeescript ember.js

基于我所读到的内容(如果我弄错了,请纠正我),处理模型应该保存的逻辑以及下一步转换的逻辑应该在路由器中.

如果是这种情况,我遇到了一个问题:我不知道如何从路线访问模型.

这是我的控制器(并且在我按下提交后控制台记录"CREATED"):

App.ScoutsNewController = Ember.ObjectController.extend
  submit: ->
    model = @get('model')
    model.on 'didCreate', ->
      console.log 'CREATED' # I want to  redirect to the index after creation
    model.save()
Run Code Online (Sandbox Code Playgroud)

我应该将这条逻辑移到路线上,对吗?我们试试看:

App.ScoutsNewRoute = Ember.Route.extend
  model: ->
    App.Scout.createRecord()

  events:
    submit: ->
      # Based on what I've read, the right place to put the code you see in the controller is here. How do I get access to the model?
      # I have tried @get('model'), @get('content')
Run Code Online (Sandbox Code Playgroud)

注意:我知道提交事件从视图,控制器,然后最终路由起泡,停在任何一个已定义"提交"的路由.因为我想要路由来处理它,我删除了控制器.我能够console.log在路线中看到任何完成,我只需要能够到达模型实例.

我正在使用 Ember v1.0.0-rc.5-7-g610589a

谢谢!

Luk*_*lia 75

两个选项:this.currentModelthis.modelFor(routeName)

更新

我和SeñorAlexMatchneer谈到了这件事.没有计划this.currentModel很快就会离开,但他认为this.modelFor(this.routeName)公共API.