我正在使用ember-data,在一个简单的类和学生示例中,我有一个处理/classes
和/classes/:class_id/students
的API。
类API请求没有任何问题,但是当我尝试列出类中的学生时,没有进行API调用。现在我不是在学生路线上手动进行API调用,因为我认为ember-data会根据模型关系进行调用。
import DS from 'ember-data';
export default DS.Model.extend({
name: DS.attr('string'),
students: DS.hasMany('student', { async: true }),
});
import DS from 'ember-data';
export default DS.Model.extend({
name: DS.attr('string'),
class: DS.belongsTo('class', { async: true }),
});
import DS from 'ember-data';
export default DS.RESTAdapter.extend({
needs: ['service:session'],
host: AppENV.APP.API_URL,
headers: function() {
return {
'accept': 'application/json',
'Content-Type': 'application/json',
'x-app-sig': this.get("session.token"),
};
}.property("session.token")
});
import Ember from 'ember';
export default Ember.ObjectController.extend({
// simplified query
all: function() {
return this.get('students');
}
}
<div class="panel__master-content">
<div class="students panel__scrollable">
{{#each all}}
{{partial 'partials/student-link'}}
{{else}}
No students currently exist <= what always gets rendered out
{{/each}}
</div>
</div>
this.resource('classes', function() {
this.resource('class', { path: '/:class_id' }, function() {
this.resource('student', { path: '/students/:student_id' }, function() {
// other stuff
});
});
});
在余烬relationship docs中,它表示期望子ID(学生)与父母一起返回。这需要吗? Ember不是智能足以通过父ID发出API请求吗?