如何使用ember.js访问嵌套索引路由中的父模型?

我有以下路线结构

App.Router.map(function(match) { this.route("days", { path: "/" }); this.resource("day", { path: "/:day_id" }, function() { this.resource("appointment", { path: "/appointment" }, function() { this.route("edit", { path: "/edit" }); }); }); }); 

当我在AppointmentIndexRoute内,我正在寻找一种方法来创build一个新的模型,使用一天(父母)模型元日,但因为天模型还不知道这个约会我不确定如何将它们关联直到约会被创build/并且提交被触发。

任何帮助将非常感激

AppointmentIndexRoute的模型钩子中,您可以使用modelFor('day')来访问父模型。 例如:

 App.AppointmentIndexRoute = Ember.Route.extend({ model: function(params) { day = this.modelFor("day"); ... } }); 

另一个例子是在这里: emberjs 1.0.0pre4你如何传递一个上下文对象到资源“…索引”路线?

如果我不使用烬数据呢? 我如何获得路线中的父母id

  this.resource('workspace',function () { this.resource('workflow', {path: '/:workspace_id/workflow'}, function () { this.route('show', {path: '/:workflow_id'}); }); }); 

这段代码将不起作用:

 App.WorkflowShowRoute = Em.Route.extend({ model: function(params) { var ws = this.modelFor('workspace'); //ws is undefined return this.store.find('workflow', params.id, ws.id); } }); 

编辑:我发现了一个解决方法,这不是理想的,但工作正是我想要的方式。

  this.resource('workspace',function () { this.route('new'); this.route('show', {path: '/:workspace_id'}); //workflow routes this.resource('workflow', {path: '/'}, function () { this.route('new', {path:'/:workspace_id/workflow/new'}); this.route('show', {path: '/:workspace_id/workflow/:workflow_id'}); }); }); 

而在我的工作stream程路线,我可以访问workspace_id强制我期望从params属性:

 App.WorkflowShowRoute = Em.Route.extend({ model: function(params) { return this.store.find('workflow', params.workflow_id, params.workspace_id); } }); 

最后,这里是我的链接到工作区内。显示路线帮手:

 {{#each workflow in workflows}} <li> {{#link-to 'workflow.show' this.id workflow.id}}{{workflow.name}}{{/link-to}} </li> {{/each}}