我有一個角色模型如下如何加載ember hasMany和belongsTo關係?
App.Person= DS.Model.extend({
id: DS.attr('string'),
name: DS.attr('string'),
visits: DS.hasMany('App.Visit'),
events: DS.hasMany('App.Event') ,
allergies: DS.hasMany('App.Allergies'),
get_allergies : function(){
return this.get('allergies').getEach('allergy_name').reduce(function(accum, item) {
return (accum.length > 0) ? (accum +', '+ item) : (item);
}, '');
}.property('[email protected]_name')
});
App.Visit = DS.Model.extend({
visit_id: DS.attr('string'),
date: DS.attr('date'),
admission: DS.belongsTo('App.Admission')
});
App.Admission = DS.Model.extend({
loc: DS.attr('string'),
admission_date: DS.attr('date'),
care_team: DS.belongsTo('App.CareTeam')
});
正如你可以看到人的hasMany「過敏」,並與人一起,過敏症也越來越因爲UI加載對我來說我打電話,而其他的get_allergies方法有許多關係,如「訪問」和「事件」沒有得到加載。
在UI {{person.get_allergies}}
我試圖側向載荷的關係「訪問」和「事件」(例如使用淨),但不工作?有人可以告訴什麼是負載數據的正確方式,因爲我不能找到任何正確的文件與網絡上的例子,除了在stackoverflow本身幾個問題?
可以嗎顯示上面的App.Admission模型?如果您手動打入REST端點,那麼json對於入場和訪問模式都會是什麼樣子? – 2013-03-05 11:46:53
@ToranBillups已更新問題 – Swapnil 2013-03-05 11:59:50
嗨Toran,我已經更新了這個問題......我只是想要一個適當的例子,在ember-data中加載關係 – Swapnil 2013-03-07 06:14:28