【发布时间】:2013-06-12 00:19:50
【问题描述】:
根据我读到的内容(如果我弄错了,请纠正我),处理何时保存模型以及下一步转换到哪里的逻辑应该在路由器中。
如果是这样的话,我遇到了一个问题:我不知道如何从路由访问模型。
这是我的控制器(在我按下提交后控制台会记录“已创建”):
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()
我应该将该逻辑移到路由中,对吗?让我们试试吧:
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')
注意:我知道提交事件从视图冒泡到控制器,最后是路由,在其中任何一个定义了“提交”的地方停止。因此,由于我希望路由处理它,因此我删除了控制器。我可以看到路由中完成的任何console.log,我只需要能够到达模型实例。
我正在使用Ember v1.0.0-rc.5-7-g610589a
谢谢!
【问题讨论】:
标签: ember.js coffeescript