找到模型后如何添加其他模型属性?(或者如何在 setupController 中访问路由的参数?
给定一条路线
this.resource('gallery', { path:'/gallery/:gallery_id' });
和一个路由器/routes/gallery.js
export default Ember.Route.extend({
model: function(params) {
return this.store.find('monkeys', { monkeyType: params.gallery_id });
//can I add an additional property to the returned model here?
},
setupController: function(controller, model) {
var pageTitle = 'something related to params.gallery_id';
//can I access route params in here?
this.controllerFor("application").set('pageTitle', pageTitle);
controller.set('model', model);
}
});
理想情况下,我想将pageTitle
应用程序控制器上的属性设置为某个gallery_id
特定的字符串,该字符串不会由 api 服务返回。
api 根据 url 返回以下内容/monkeys?monkeyType=someId
{ "monkeys":[{ ... }, { ... }] }