2013-09-21 105 views
0

這裏的JSON灰燼數據屬性不被駱駝

{ 
    "users": [ 
     { 
      "id": "10", 
      "email": "[email protected]", 
      "activated": true, 
      "created_at": "2013-08-25 19:30:16", 
      "username": "Roober" 
     } 
    ] 
} 

這個工程的一個樣本:

App.User = DS.Model.extend({ 
    username: DS.attr(), 
    email: DS.attr(), 
    activated: DS.attr(), 
    created_at: DS.attr() 
}); 

這不:

App.User = DS.Model.extend({ 
    username: DS.attr(), 
    email: DS.attr(), 
    activated: DS.attr(), 
    createdAt: DS.attr() 
}); 

createdAt返回undefined。

灰燼是V1.0.0和灰燼數據是V1.0.0,beta.2

回答

3

灰燼數據Beta 1的期望從你的服務器在默認情況下 駝峯匹配響應,但你可以實現標準化的方法來改變這種狀況:

normalize: function(type, hash, property) { 
    var json = { id: hash.id }; 

    for (var prop in hash) { 
     json[prop.camelize()] = hash[prop]; 
    } 

    return this._super(type, json, property); 
} 

您可以查看此文檔以獲取更多信息https://github.com/emberjs/data/blob/master/TRANSITION.md

+0

謝謝。這意味着文檔是錯誤的http://emberjs.com/guides/models/the-rest-adapter/#toc_underscored-attribute-names –

+0

在最新的版本中,「DS.ActiveModelAdapter」和「DS.ActiveModelSerializer」也一直在工作對我來說 – chopper

+0

我認爲他們必須努力逐步淘汰這個特定的文件。它沒有鏈接到任何菜單中,我已經提交了幾個pull請求來糾正該頁面,即使它們更新了頁面以準確反映當前功能,它們也沒有被接受幾周。 –