[英]ember route pass dynamic url to child route
如果我在下面定義了路線:
App.Router.map(function () {
this.resource('user', {path: "/:user"}, function () {
this.route('work', {path: "/work"});
})
});
我可以在用戶控制器中獲取:user值,但是如何在工作控制器或工作路徑中獲取此值?
您可以在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);
}
您可以通過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.