余烬数据错误:适配器的响应没有任何数据



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

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

生成此错误:"处理路由时出错:blogs.index 断言失败:您对 ID 为 14 的博客发出了findRecord请求,但适配器的响应没有任何数据"。

但是数据正在到达,并且采用以下格式:

{ "博客": { "id": 14, "person_id": "1", "访问":"3" } }

我的适配器在应用程序/适配器中指定为.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的开发者工具中查看时返回的有效负载(联系人表只有一条记录):

{
"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);
}
});

最新更新