2014-03-28 21 views
1

我的問題是符合這一個:Ember data 1.0.0: confused with per-type adapters and serializersEmber數據1.0應用程序-en AdapterSerializer不工作?

問題是,因爲我需要設置ActiveModelSerializer我不能初始化每個類型RESTSerializer:

App.FooSerializer = DS.ActiveModelSerializer.extend({attrs: {}}); 

嵌入到一組關係。

所以我想爲所有型號設置1個序列化器。我試圖設置ApplicationSerializer,但得到從服務器的響應時,這並沒有調用任何掛鉤(我敢肯定,我的服務器提供了正確的響應):

App.ApplicationSerializer = DS.RESTSerializer.extend({ 
    extractSingle: function(store, type, payload, id, requestType) { 
     return this._super(store, type, payload, id, requestType); 
    }, 
    extractArray: function(store, type, payload, id, requestType) { 
     return this._super(store, type, payload, id, requestType); 
    }, 
    normalize: function(type, property, hash) { 
     return this._super(type, property, hash); 
    } 
}); 

設置我的適配器似乎不工作:

var adapter = require('init/adapter'); 

    App.ApplicationAdapter = adapter.extend({ 
     defaultSerializer: myAdapter //I QUESS THIS IS WRONG? 
    }); 

我是否犯了語法錯誤?還有其他建議嗎?

編輯:

好吧,我發現我的錯誤,但不是一個很好的解決方案。似乎我的FooSerializer覆蓋了一般的ApplicationSerializer ..

有沒有一種方法可以同時設置? :/

回答

2

你不能同時使用這兩種方法,但你可以讓你的FooSerializer擴展你的ApplicationSerializer,然後覆蓋你想要以不同方式使用的方法。

App.FooSerializer = App.ApplicationSerializer.extend({ 
    extractArray: function(store, type, payload, id, requestType) { 
    // alert each record to annoy the user 
    return this._super(store, type, payload, id, requestType); 
    }, 
});