我有這樣的代碼在灰燼路線:如何獲取Ember路線中資源的關係?
let forum = this.store.findRecord('forum', 'main').then(function(forum) {
console.log('FORUM:', forum);
let categories = forum.get('categories');
console.log('CATEGORIES:', categories);
});
return forum;
此控制檯返回此:
FORUM: Object { store: Object, _internalModel: Object, id: Getter, currentState: Object, isError: false, adapterError: null, OWNER [id=__ember1476462923058714220863537]: Object, _super: ROOT(), 2 more… }
CATEGORIES: undefined
Obvisouly,請求到/forums/main
取得,但沒有之後。 forum.get('categories')
有什麼作用?我該如何獲得資源的關係?不應該要求/forums/main/categories
?
論壇:
export default DS.Model.extend({
// Attributes
language: DS.attr('string'),
// Relationships
categories: DS.hasMany('category', { async: true }),
});
類別:
export default DS.Model.extend({
// Attributes
name: DS.attr('string'),
// Relationships
forum: DS.belongsTo('forum', { async: true }),
boards: DS.hasMany('board', { async: true })
});
路由器(相關部分):
this.route('community', function() {
this.route('players');
this.route('forum', function() {
});
});
昨天有類似的話題,有更復雜的[question](http://stackoverflow.com/questions/40032747/ember-2-filter-relationship-models-hasmany-belongsto-and-calculte-computed-p)。你可以嘗試看看。 – Keo
我們還需要您的模型定義才能在此爲您提供合適的幫助。主要我們需要知道您的論壇類別關係是如何定義的。 –
我編輯了我的問題。 –