2014-04-04 22 views
3

「我試圖使Emberjs與fortunejs後端一起工作。到目前爲止,我在Ember中做了一個非常簡單的頁面,該頁面應該顯示所有'客戶'實體,它們與LSadapter一起工作良好。「斷言失敗:來自findAll的響應必須是數組,而不是未定義的」

當我的應用程序加載概述頁面,它做一個GET請求http://localhost:1337/customers和財富與迴應:

{ 
"customers": [ 
{ 
    "id": "YIR17juOFkaWBFhl", 
    "name": "PIm", 
    "phone": 132, 
    "fax": 123, 
    "chamberOfCommerceNumber": 123, 
    "website": "123.nl" 
}, 
{ 
    "id": "gUGIoHvwI8mwVTgE", 
    "name": "Marco", 
    "phone": 123, 
    "fax": 123, 
    "chamberOfCommerceNumber": 123, 
    "website": "it.nl" 
}]} 

然而,燼似乎並不喜歡它,並給了我:

「聲明失敗:來自findAll的響應必須是數組,而不是 undefined」

我以爲這個是正確的json格式燼從期望得到所有客戶的請求,出了什麼問題?

僅供參考,我創建了一個可以在fortunejs下正常工作的創建頁面。爲此,我必須像這樣修改RESTSerializer:

App.ApplicationSerializer = DS.RESTSerializer.extend({ 
serialize: (record, options) -> 
    [this._super record, options] #Turn into array 

serializeIntoHash: (hash, type, record, options) -> 
    console.log type.typeKey 
    type.typeKey = Ember.Inflector.inflector.pluralize type.typeKey #pluralize root key 
    console.log type.typeKey 
    console.log record 
    result = this._super hash, type, record, options 

}); 

但是,這應該與傳入的JSON形式的api無關。

任何想法出了什麼問題?

回答

0

我知道這是老了,我不知道堆棧溢出的這一政策,但我曳通過懸而未決的問題,看看我是否知道任何把我的頭頂部...

我覺得這裏的問題是findAll(它在當前版本的Ember Data中不存在)是一種只能存儲查找的方法。當前版本(http://emberjs.com/api/data/classes/DS.Store.html#method_all)中的store.all的等效值。

您需要store.find,它會爲數據發出後端服務器請求(http://emberjs.com/api/data/classes/DS.Store.html#method_find)。

希望這有助於任何人絆倒這個問題...

相關問題