具有动态段的资源并在嵌套路径中检索模型

Dam*_*IEU 3 ember.js ember-router

我有以下路线:

@resource 'groups', {path: 'events/:event_id/groups'}, ->
  @route 'new'
Run Code Online (Sandbox Code Playgroud)

在我的新路径中,为了构建一个新的App.Group对象,我需要知道我们所处的事件.

所以我有以下路线,它对应于资源:

App.GroupsRoute = Ember.Route.extend
  model: (params) ->
    App.Event.find params.event_id
Run Code Online (Sandbox Code Playgroud)

和路线对应的那个:

App.GroupsNewRoute = Ember.Route.extend
  model: ->
    App.store.createRecord App.Group
Run Code Online (Sandbox Code Playgroud)

我需要在创建时指定组的事件.但是,在GroupsNewRoute中,我似乎无法检索事件.参数不包括在内event_id.

如何从路径中的父资源获取模型?

Yeh*_*atz 8

这里有几个不同的问题:

你不应该使用App.store.商店应该在路线上可用this.get('store').

我不确定你为什么要命名你的路线GroupsRoute.因为它代表一个事件,你应该命名它EventRoute.这不是必需的,但它更具惯用性.此外,您无需为其指定模型GroupsRoute.你正在做的是默认行为.

最后,您可以通过以下方式获取另一条路线的模型:this.modelFor('groups')在您的路线中.这应该解决你的问题.