如何将 url 中的动态段传递给组件?我可以在我的模型中获取参数,但我不知道如何将其传递给组件。我现在做的是:
export default Ember.Route.extend({
sectionId: 0,
model(params) {
this.set('sectionId', params.section_id);
return this.store.findAll('content');
}
});
在模板中:
{{#component id=sectionId}}{{/component}}
但是当我在组件中记录 id 时,它显示未定义。
最佳答案
您可以在 setupController
Hook 中设置 Controller 属性。
export default Ember.Route.extend({
sectionId: 0,
model(params) {
this.set('sectionId', params.section_id);
return this.store.findAll('content');
},
setupController(controller, model) {
controller.set('sectionId', this.get('sectionId'));
}
});
关于javascript - 如何将动态段传递给 ember 组件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34159674/