Ember错误地反序列化json数据

时间:2016-08-06 21:30:41

标签: json ember.js ember-data

所以我有一个Spring Boot api在列表中返回一堆记录,如:

chartSeries(hist.xts, type = 'bars', TA = NULL)

但是当我尝试在模板中阅读时,我收到以下错误

[
  {
    "uid": 16587783,
    "createdAt": 1391708660000,
    "name": "FRaaS",
    "fullName": "caarlos0/FRaaS",
    "description": "Fake RT as a Service",
    "homepage": "http://fraas.herokuapp.com/",
    "owner": "caarlos0",
    "organization": null,
    "joined": false,
    "private": false
  },
  ....
  more records
]

这是我当前的适配器

WARNING: Encountered "0" in payload, but no model was found for model name "0" (resolved model name using chathub-ember@serializer:-rest:.modelNameFromPayloadKey("0"))

我可以在ember中做什么来允许它在我发送时读取数据?如果需要,我可以更改API,但我不想

1 个答案:

答案 0 :(得分:1)

您需要使用RESTSerializerprimaryKey用于序列化程序而非适配器。我想你在你的应用程序中使用了json序列化程序。

<强>更新

将以下内容添加到您的应用程序序列化程序

normalizeSingleResponse(store, primaryModelClass, payload, id, requestType) {
        let typeKey = primaryModelClass.modelName;
        let ret = {};
        ret[typeKey] = payload;
        return this._normalizeResponse(store, primaryModelClass, ret, id, requestType, true);
    },

    normalizeArrayResponse(store, primaryModelClass, payload, id, requestType) {
        let pluralTypeKey = Ember.Inflector.inflector.pluralize(primaryModelClass.modelName);
        let ret = {};
        ret[pluralTypeKey] = payload;
        return this._normalizeResponse(store, primaryModelClass, ret, id, requestType, false);
    }