2014-01-12 29 views
4

我使用的是餘燼數據1.0.0-beta.4。在更新它發送PUT請求與以下JSON餘燼數據REST更改JSON

{ 「屬性」:{ 「名」: 「姓名」, 「年齡」: 「22」}}

我RESTAdapter如何改變發送以下JSON代替上述

{ 「名」: 「姓名」, 「年齡」: 「22」}

請幫

謝謝

回答

2

創建一個自定義序列化器並覆蓋serializeIntoHash掛鉤,這樣的事情應該這樣做(我沒有測試這個)。

瞭解更多關於串行這裏:https://github.com/emberjs/data/blob/master/TRANSITION.md

App.PropertySerializer = DS.RESTSerializer.extend({ 
    serializeIntoHash: function(data, type, record, options) { 
    var root = Ember.String.decamelize(type.typeKey), 
     properties = this.serialize(record, options); 
    for(var prop in properties){ 
     if(properties.hasOwnProperty(prop)){ 
     data[prop] = properties[prop]; 
     } 
    } 
    } 
});