2017-10-19 65 views
0

所以我想在ember中使用ember数据构建下面的select下拉列表,并且API将使用JSON API规范。下面是一个截图例子 Select DropdownJSON API组和子组EmberJS

所以我会在服务模式,状态下面

应用程序/模型/ service.js

category: DS.belongsTo('category'), 
subCategory: DS.belongsTo('sub-category') 

应用程序/模型/ category.js

service: DS.hasMany('service'), 
subCategory: DS.belongsTo('category') 

app/model/category.js

service: DS.hasMany('service'), 
category: DS.belongsTo('sub-category') 

我觉得我错过了什么?思考

回答

0

我觉得想你错过的是:

export DS.Model.extend({ 
    parent: DS.belongsTo('category', { inverse: 'children'}), 
    children: DS.hasMany('category', { inverse: 'parent' }), 
}); 

,这将让你有一个模型中的父/子关系。如果你想要一个不同的子类别的模型,我真的不明白你的问题是什么。