“findAll的响应必须是Array,而不是未定义” - 潜在错误的序列化? [英] "The response from a findAll must be an Array, not undefined" - potentially incorrect serialisation?
问题描述
刚开始使用Ember,我正在关注本教程。
Just getting started with Ember, and I'm following this tutorial.
我已经设置了Ember应用程序,路由和模型,除了当我打路线时,我收到大量警告打印到控制台,其次是标题中的错误
I've got the Ember app set up, the Route and the Model, except when I hit the Route, I get a large number of warnings printed to the console, followed by the error in the title.
我的模型看起来像:
App = DS.Model.extend
firstName: DS.attr('string')
lastName: DS.attr('string')
email: DS.attr('string')
phone: DS.attr('string')
status: DS.attr('string', defaultValue: 'new')
notes: DS.attr('string')
我的路线:
App.LeadsRoute = Ember.Route.extend
model: -> @store.find 'lead'
我的Store.js:
My Store.js:
App.ApplicationStore = DS.Store.extend({
})
# Override the default adapter with the `DS.ActiveModelAdapter` which
# is built to work nicely with the ActiveModel::Serializers gem.
App.ApplicationAdapter = DS.ActiveModelAdapter.extend({
})
JSON我的Rails应用程序返回看起来像这样。
The JSON my Rails app is returning looks like this.
警告是:
WARNING: Encountered "0" in payload, but no model was found for model name "0" (resolved model name using DS.ActiveModelSerializer.typeForRoot("0"))
(我为数据库中的每个线索收到一个警告)
(I get one warning for each Lead in the Database)
错误是:
Error while processing route: leads Assertion Failed: The response from a findAll must be an Array, not undefined Error: Assertion Failed: The response from a findAll must be an Array, not undefined
这似乎是一个很常见的一个,如果StackOverflow搜索是要做的事情:)
Which seems to be a pretty common one, if StackOverflow search is anything to go by :)
非常感谢!
谢谢,
Nik
推荐答案
好吧,所以我想出了这一个...列表响应, -data / ActiveModelAdapter预期的格式如下:
Ok, so I figured this one out... for list responses, ember-data/ActiveModelAdapter is expecting responses formatted like this:
{ "leads" : [ { id: 123, name: "Test", ... }, { id: 456, name: "Test 2", ... } ] }
而我正在发送
[ { "lead": { id: 123, name: "Test", ... } }, { "lead": { id: 456, name: "Test 2", ... }} ] }
这篇关于“findAll的响应必须是Array,而不是未定义” - 潜在错误的序列化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!