0
我正試圖擺脫Ember-Data中的一些異步關係,並將它們加載,但卻遇到了一些問題。使用Ember Dataloading加載
我的API發回相關數據,但記錄是返回的每個對象上的屬性,而不是根上的單獨數組/對象。我正在使用extractArray
來挖掘數據,所以ED喜歡它,但不能完全正確。下面是從API返回的數據樣本:
{
"record": [
{
"id": 2,
"name": "3M Aerospace",
"currency": 6,
"paymentTerms": 3,
"Currencies_by_currency": {
"id": 6,
"currency": "USD",
"description": "US Dollar",
"sortOrder": 1
},
"PaymentTerms_by_paymentTerms": {
"id": 3,
"term": "NET10",
"description": "Due with 10 days of invoice date"
"sortOrder": 3
}
},
{
"id": 3,
"name": "BAE Aerospace",
"currency": 6,
"paymentTerms": 3,
"Currencies_by_currency": {
"id": 6,
"currency": "USD",
"description": "US Dollar"
"sortOrder": 1
},
"PaymentTerms_by_paymentTerms": {
"id": 3,
"term": "NET10",
"description": "Due with 10 days of invoice date"
"sortOrder": 3
}
}
]
}
我知道我需要Countries_by_mailingAddressCountry
,Currencies_by_currency
,並且PaymentTerms_by_paymentTerms
出來的對象根。他們到底應該去哪裏?我認爲它應該是:
{
"record": [
{
"id": 2,
// other data...
"currency": 6,
"paymentTerms": 3,
// more data...
}, {
"id": 3,
// other data...
"currency": 6,
"paymentTerms": 3,
// more data...
}
],
"currencies": [
{
"id": 6,
"currency": "USD",
"description": "US Dollar",
"sortOrder": 1
}
],
"paymentTerms": [
{
"id": 3,
"term": "NET10",
"description": "Due with 10 days of invoice date",
"isActive": true,
"sortOrder": 3
}
]
}
但ED抱怨說它無法找到相關數據。該模型被定義爲
App.Vendor = DS.Model.extend(App.Addressable, {
name: DS.attr('string'),
currency: DS.belongsTo('currency'),
paymentTerms: Ds.belongsTo('payment-term')
});
App.Currency = DS.Model.extend({
currency: string,
description: string,
sortOrder: number,
});
App.PaymentTerm = DS.Model.extend({
term: string,
description: string,
sortOrder: number,
});
在您的JSON輸出中是''record''應該是'「vendors」'? – 2014-12-01 19:31:12
是的,就是這樣。在發佈後找出它。我正在盤旋,以適當的格式更新此問題。我不得不重構我的適配器的大部分,以使sideloading正常工作。 – ultimatemonty 2014-12-01 19:37:47