ここにあるドキュメントに基づいて:https://guides.emberjs.com/v2.5.0/models/customizing-serializers/#toc_jsonserializer JSONSerializerは私のAPIに使用するための正しいシリアライザです。JSONSerializer EmberJSが予想される形式を受け入れていません
私は、次のエラーが表示されているにもかかわらず:
ember.debug.js:28535 Error while processing route: core.admin.users Cannot read property 'type' of undefined TypeError: Cannot read property 'type' of undefined
APIの応答は次のようになります。
import Model from 'ember-data/model';
import attr from 'ember-data/attr';
export default Model.extend({
first_name: attr('string'),
last_name: attr('string')
});
マイアプリケーションアダプタ:
{
"errors": [],
"data": [
{
"id": 1,
"first_name": "Foo",
"last_name": "Bar"
},
{
"id": 2,
"first_name": "Moo",
"last_name": "Boo"
}
],
"version": 1
}
私のモデルはそうのようになります。
import RESTAdapter from 'ember-data/adapters/rest';
export default RESTAdapter.extend({
headers: {
'Accepts': 'application/json',
'Accept': 'application/json'
}
});
マイユーザーアダプタ:
import ApplicationAdapter from './application';
export default ApplicationAdapter.extend({
buildURL: function(){
return 'core/users/foobar';
}
});
そして最後に私のアプリケーションシリアライザ:
import JSONSerializer from 'ember-data/serializers/json';
export default JSONSerializer.extend({
});
あなたは完全にラックスです。私は自分のオブジェクトからID属性も忘れていました。上記の質問を修正します – valanto