如何将网址中的动态细分传递给组件?我可以在模型中获取参数,但我不知道如何将其传递给组件。我现在做的是:
CREATE TABLE EXAM
(Student_id char(5), NOT NULL
Module_code varchar(6), NOT NULL
Exam_year smallint, NOT NULL
Score smallint, NOT NULL
PRIMARY KEY (Student_id, Module_code) -- Creates a unique tuple
FOREIGN KEY (Student_id) REFERENCES STUDENT(Student_id) -- Enforces data integrity
FOREIGN KEY (Module_code) REFERENCES MODULE(Module_code) -- Enforces data integrity
);
在模板中:
export default Ember.Route.extend({
sectionId: 0,
model(params) {
this.set('sectionId', params.section_id);
return this.store.findAll('content');
}
});
但是当我在我的组件中记录id时,它表示未定义。
答案 0 :(得分:3)
您可以在setupController
挂钩中设置控制器属性。
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'));
}
});
答案 1 :(得分:0)
Your controller can have access to the params,所以请务必在控制器中声明。
例如,对于您的控制器:
export default Ember.Controller.extend({
queryParams: ['section'],
section: null
});
在你的模板中:
{{#component id=section}}{{/component}}
请注意,这是假设您的网址看起来像http://example.com/posts/1?section=3