-------------------------------
Ember : 1.13.11
Ember Data : 1.13.15
Firebase : 2.3.2
EmberFire : 1.6.3
jQuery : 1.11.3
-------------------------------
I've got two endpoints in my firebase app. /employees
and /subjects
. In my ember app I want to add subjects to an employee (employees/$id/subjects
). The problem is, I don't know how to load all my subjects from /subjects
so I can add them to my array.
我的firebase应用程序中有两个端点。 /员工和/科目。在我的余烬应用程序中,我想向员工添加主题(员工/ $ id / subject)。问题是,我不知道如何从/科目加载我的所有科目,所以我可以将它们添加到我的阵列。
This is my routes:
这是我的路线:
Router.map(function() {
this.route('dashboard');
this.route('employees', function() {
this.route('employee', { path: '/:id'});
});
});
And this is my model
这是我的模特
export default Ember.Route.extend({
model(params) {
return this.store.findRecord('employee', params.id);
}
});
I've tried various things to get this to work, creating a subroute this.route(employee, function(){ this.route('subjects') }
, loading a second model in my employee model, none of which has worked. I'm new to ember so I might have gotten some things mixed up. Any helps is appreciated.
我已经尝试了各种方法来实现这一点,创建了一个子路由this.route(employee,function(){this.route('subject')},在我的员工模型中加载第二个模型,但没有一个有效。我是新手,所以我可能会把一些东西搞混了。任何帮助都值得赞赏。
EDIT
编辑
Employee model
员工模型
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})
});
Subject Model
主题模型
export default DS.Model.extend({
name: DS.attr('string')
});
To maybe describe my intentions a bit better, here is the flow I want:
为了更好地描述我的意图,这是我想要的流程:
User selects an employee, employees info is shown along with a list of subjects assigned to that employee. But I also need the full list of subjects available, if I want to assign a new subject to an employee. Hence my question. Hope this makes sense
用户选择员工,显示员工信息以及分配给该员工的主题列表。但是,如果我想为员工分配新主题,我还需要完整的主题列表。因此我的问题。希望这是有道理的
1 个解决方案
#1
1
Okay, then you can do this in your Route:
好的,那么你可以在你的路线上做到这一点:
export default Ember.Route.extend({
model(params) {
return Ember.RSVP.hash({
employee: this.store.findRecord('employee', params.id),
subjects: this.store.findAll('subject')
});
}
});
then in your template:
然后在你的模板中:
{{#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}}
#1
1
Okay, then you can do this in your Route:
好的,那么你可以在你的路线上做到这一点:
export default Ember.Route.extend({
model(params) {
return Ember.RSVP.hash({
employee: this.store.findRecord('employee', params.id),
subjects: this.store.findAll('subject')
});
}
});
then in your template:
然后在你的模板中:
{{#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}}