EmberFire 添加来自不同模型的关系
EmberFire Adding relationship from different model
-------------------------------
Ember : 1.13.11
Ember Data : 1.13.15
Firebase : 2.3.2
EmberFire : 1.6.3
jQuery : 1.11.3
-------------------------------
我的 firebase 应用程序中有两个端点。 /employees
和 /subjects
。在我的 ember 应用程序中,我想为员工添加主题 (employees/$id/subjects
)。问题是,我不知道如何从 /subjects
加载我所有的主题,所以我可以将它们添加到我的数组中。
这是我的路线:
Router.map(function() {
this.route('dashboard');
this.route('employees', function() {
this.route('employee', { path: '/:id'});
});
});
这是我的模型
export default Ember.Route.extend({
model(params) {
return this.store.findRecord('employee', params.id);
}
});
我已经尝试了各种方法来让它工作,创建了一个子路径 this.route(employee, function(){ this.route('subjects') }
,在我的员工模型中加载了第二个模型,none 成功了。我是 ember 的新手,所以我可能混淆了一些东西。任何帮助表示赞赏。
编辑
员工模型
export default DS.Model.extend({
name: DS.attr('string'),
position: DS.attr('string'),
accessoryPosition: DS.attr('string'),
education: DS.attr('string'),
experience: DS.attr('string'),
imgUrl: DS.attr('string'),
subjects: DS.hasMany('subject', {async: true})
});
主题模型
export default DS.Model.extend({
name: DS.attr('string')
});
为了更好地描述我的意图,这是我想要的流程:
用户选择一名员工,员工信息与分配给该员工的主题列表一起显示。但如果我想为员工分配一个新主题,我还需要可用主题的完整列表。因此我的问题。希望这是有道理的
好的,那么你可以在你的路线中这样做:
export default Ember.Route.extend({
model(params) {
return Ember.RSVP.hash({
employee: this.store.findRecord('employee', params.id),
subjects: this.store.findAll('subject')
});
}
});
然后在您的模板中:
{{#each employee.subjects as |subject|}}
{{!these are your employee subjects}}
{{subject.name}}
{{/each}}
{{#each subjects as |subject|}}
{{!these are all your subjects}}
{{subject.name}}
{{/each}}
-------------------------------
Ember : 1.13.11
Ember Data : 1.13.15
Firebase : 2.3.2
EmberFire : 1.6.3
jQuery : 1.11.3
-------------------------------
我的 firebase 应用程序中有两个端点。 /employees
和 /subjects
。在我的 ember 应用程序中,我想为员工添加主题 (employees/$id/subjects
)。问题是,我不知道如何从 /subjects
加载我所有的主题,所以我可以将它们添加到我的数组中。
这是我的路线:
Router.map(function() {
this.route('dashboard');
this.route('employees', function() {
this.route('employee', { path: '/:id'});
});
});
这是我的模型
export default Ember.Route.extend({
model(params) {
return this.store.findRecord('employee', params.id);
}
});
我已经尝试了各种方法来让它工作,创建了一个子路径 this.route(employee, function(){ this.route('subjects') }
,在我的员工模型中加载了第二个模型,none 成功了。我是 ember 的新手,所以我可能混淆了一些东西。任何帮助表示赞赏。
编辑
员工模型
export default DS.Model.extend({
name: DS.attr('string'),
position: DS.attr('string'),
accessoryPosition: DS.attr('string'),
education: DS.attr('string'),
experience: DS.attr('string'),
imgUrl: DS.attr('string'),
subjects: DS.hasMany('subject', {async: true})
});
主题模型
export default DS.Model.extend({
name: DS.attr('string')
});
为了更好地描述我的意图,这是我想要的流程:
用户选择一名员工,员工信息与分配给该员工的主题列表一起显示。但如果我想为员工分配一个新主题,我还需要可用主题的完整列表。因此我的问题。希望这是有道理的
好的,那么你可以在你的路线中这样做:
export default Ember.Route.extend({
model(params) {
return Ember.RSVP.hash({
employee: this.store.findRecord('employee', params.id),
subjects: this.store.findAll('subject')
});
}
});
然后在您的模板中:
{{#each employee.subjects as |subject|}}
{{!these are your employee subjects}}
{{subject.name}}
{{/each}}
{{#each subjects as |subject|}}
{{!these are all your subjects}}
{{subject.name}}
{{/each}}