經過我整天的嘗試,我放棄了。對於ember.js中的一個非常基本的應用程序,我嘗試設置一個ajax請求給服務器,並用適當的答覆來回答。問題不在於從服務器中獲取模型數據(custom_route),而是顯示在陣列控制器的模板中。但我無法獲取的是相關模型(站)的數據。 兩個型號都definded如下:如何正確設置具有hasMany關係的ember-data的ajax-request?
App.CustomRoute = DS.Model.extend({
name: attr('string'),
description: attr('string'),
stations: DS.hasMany(App.Station)
});
App.Station = DS.Model.extend({
name: attr('string'),
description: attr('string'),
stations: DS.hasMany(App.Station)
});
使用FixtureAdapter一切加{異步:真正}後工作完全正常作爲參數傳遞給這兩種方法。但是使用默認的RESTful適配器,我顯示的唯一東西是來自custom_route模型的數據。這使我想到了我的問題:ajax回覆如何看起來像適配器從兩個模型中獲取數據。 在網絡上,我找不到一個如何回覆findAll()請求來解析模型及其相關模型的示例。一切,我發現只有examplifies答覆應該怎麼樣子(包括側向載荷)如果單個模塊的請求被解僱 我曾試圖
{
"custom_routes": [
{
"custom_route": {
"id": 1,
"name": "Route 1",
"description": "Description 1",
"station_ids": [
1,
2,
3
]
}
}
],
"stations": [
{
"id": 1,
"name": "Station 1",
"description": "Description 1",
}
]
}
,但沒有奏效。但是,如果模型的單個模型的關鍵字「custom_route」位於「custom_routes」條目的左側,則會顯示。 希望有一個解決這個問題的方法,希望我的英語能夠描述這個問題。我既不是母語人士,也不是長期的網絡開發人員。但是,期待改善雙方:)
我知道了......在發佈我的問題後,我找到了解決方案。正確的應答具有看起來如下: '{ 「custom_routes」:[ { 「ID」:1, 「名稱」: 「路徑1」, 「描述」: 「說明1」, 「站「:[ 1, 2,] } ], 」站「:[ { 」ID「:1, 」名稱「: 」站1「, 」說明「:」 描述1「, } ] }' Thanks for your pat ience。 –