emberjs 1.0.0pre4 how do you pass a context object to a resource “…Index” route?

时光总嘲笑我的痴心妄想 提交于 2020-01-04 04:19:19

问题


In a simple ember application I have a single resource ('detail') with an index template. In the application index template I have a button which calls transitionTo('detail',obj) on the index controller, where obj is the content item that was clicked. This passes obj as the model argument to my DetailRouter.setupController function, but NOT to my DetailIndexRouter.setupController function. How can I pass my context object all the way through to the 'leaf' route?

I have seen a similar question asked here, but I am working with a dynamic segment in the route.

Here is a jsfiddle.


回答1:


To set the model for the DetailIndexRouter, override it's model hook and then use modelFor('detail') to access the content item from the parent route. So for example:

App.DetailIndexRoute = Ember.Route.extend({
  model: function(params) {
    return this.modelFor("detail");
  }
});

Updated fiddle here: http://jsfiddle.net/Qw8Q3/2/



来源:https://stackoverflow.com/questions/14609757/emberjs-1-0-0pre4-how-do-you-pass-a-context-object-to-a-resource-index-rout

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!