[英]ember route pass dynamic url to child route
if I have defined routes below: 如果我在下面定义了路线:
App.Router.map(function () {
this.resource('user', {path: "/:user"}, function () {
this.route('work', {path: "/work"});
})
});
I can get the :user value in user controller,but How can I get this value in my work controller or work route? 我可以在用户控制器中获取:user值,但是如何在工作控制器或工作路径中获取此值?
You could use modelFor
in route and set user
controller property in model
(or beforeModel
, afterModel
) hook: http://emberjs.com/api/classes/Ember.Route.html#method_modelFor 您可以在route中使用modelFor
,并在model
(或beforeModel
, afterModel
)挂钩中设置user
控制器属性: http : afterModel
//work route
model: function() {
return Ember.RSVP.hash({
user: this.modelFor('user'), // here user is routeName
work: // your logic here
});
},
setupController: function(controller, models) {
controller.setProperties(models);
}
You can set it on the controller from the work route in the setupController
hook: 您可以通过setupController
钩子中的工作路径在控制器上对其进行设置:
setupController(controller) {
controller.set('userId', this.modelFor('user').get('id'));
return this._super(...arguments);
}
// ES < 6 syntax
setupController: function(controller) {
controller.set('userId', this.modelFor('user').get('id'));
return this._super.apply(this, arguments);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.