Ember data Error: the adapter's response did not have any data

Ember data Error: the adapter's response did not have any data

我刚刚将应用程序从 Ember 1.13 升级到 Ember 2.12。现在我加载数据存储的尝试失败了。这一行:

return this.store.find('blog', 14);

生成此错误:"Error while processing route: blogs.index Assertion Failed: You made a findRecord request for a blog with id 14, but the adapter's response did not have any data"。

但是数据正在到达,格式如下:

{ "blogs":{ "id": 14, "person_id": "1", "access": "3" } }

我的适配器在 application/adapter.js 中指定为:

导出默认值 DS.RESTAdapter.extend({

主持人:“http://localhost”, 命名空间:'api-rick'

});

有人知道我为什么会收到这个错误吗?我认为 JSON 格式正确——在我升级 Ember 之前没有任何问题。

稍后编辑,这里是相关代码:

//application/adapter.js
import DS from 'ember-data';
import Ember from 'ember';
export default DS.RESTAdapter.extend({

  host: "http://localhost",
  namespace: 'api-rick',

  pathForType: function(type) {
    //this so types (db table names) are singular;
    //else are pluralized in Adapter's request
    return Ember.String.singularize(type);
  }
});

//application/serializer.js
port DS from 'ember-data';

export default DS.RESTSerializer.extend({
});

//pods/contact/model.js
import DS from 'ember-data';

export default DS.Model.extend({
  name         : DS.attr(),
});

//pods/contact/route.js
import Ember from 'ember';

export default Ember.Route.extend({
  model: function() {
    return this.store.findAll('contact');
  },
});

//在Chrome的开发者工具中查看返回的payload(联系人table只有一条记录):

{
    "contact": [
        {
            "id": 1,
            "name": "Bilbo the duck"
        }
    ]
}

最后,Chrome 控制台报错如下:

Transition #0: contact: calling beforeModel hook
ember.debug.js:55891 
Transition #0: contact: calling deserialize hook
ember.debug.js:28573 
Error while processing route: contact Assertion Failed: You made a `findAll` request for contact records, but the adapter's response did not have any data Error
    at assert (http://localhost:4200/assets/vendor.js:20732:13)
    at Object.assert (http://localhost:4200/assets/vendor.js:32400:34)
    at assert (http://localhost:4200/assets/vendor.js:85626:37)
    at http://localhost:4200/assets/vendor.js:97389:41
    at tryCatch (http://localhost:4200/assets/vendor.js:73561:14)
    at invokeCallback (http://localhost:4200/assets/vendor.js:73576:15)
    at publish (http://localhost:4200/assets/vendor.js:73544:9)
    at http://localhost:4200/assets/vendor.js:53448:16
    at invokeWithOnError (http://localhost:4200/assets/vendor.js:15377:16)
    at Queue.flush (http://localhost:4200/assets/vendor.js:15436:9)

如果您的后端使用下划线进行响应,那么您需要使用以下代码,

import DS from 'ember-data';

export default DS.RESTSerializer.extend({
  keyForAttribute: function(attr, method) {
    return Ember.String.underscore(attr);
  }
});