刚开始使用Ember,我跟随this tutorial。
我已经设置了Ember应用程序,路线和模型,除非我点击路线时,我会在控制台上打印大量警告,然后是标题中的错误。
我的模型看起来像:
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:
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 my Rails应用返回外观like this。
警告是:
WARNING: Encountered "0" in payload, but no model was found for model name "0" (resolved model name using DS.ActiveModelSerializer.typeForRoot("0"))
(我收到数据库中每个潜在客户的一个警告)
错误是:
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搜索可以通过:)
非常感谢!
谢谢,
的Nik
答案 0 :(得分:1)
好的,所以我想出了这个...对于列表响应,ember-data / ActiveModelAdapter期待响应格式如下:
{ "leads" : [ { id: 123, name: "Test", ... }, { id: 456, name: "Test 2", ... } ] }
我正在发送
[ { "lead": { id: 123, name: "Test", ... } }, { "lead": { id: 456, name: "Test 2", ... }} ] }