javascript - "Assertion Failed: The response from a findAll must be an Array, not undefined"

标签 javascript json ember.js ember-data

我正在尝试让 Emberjs 与 fortunejs 后端一起工作。到目前为止,我在 Ember 中制作了一个非常简单的页面,它应该显示所有“客户”实体,这与 LSadapter 配合得很好。

当我的应用程序加载概览页面时,它向 http://localhost:1337/customers 发出 GET 请求,fortune 响应:

{
"customers": [
{
  "id": "YIR17juOFkaWBFhl",
  "name": "PIm",
  "phone": 132,
  "fax": 123,
  "chamberOfCommerceNumber": 123,
  "website": "123.nl"
},
{
  "id": "gUGIoHvwI8mwVTgE",
  "name": "Marco",
  "phone": 123,
  "fax": 123,
  "chamberOfCommerceNumber": 123,
  "website": "it.nl"
}]}

然而,ember 似乎并不喜欢它并给了我:

"Assertion Failed: The response from a findAll must be an Array, not undefined"

我认为这是 ember 期望从 get 请求获取所有客户的正确 json 格式,出了什么问题?

仅供引用,我制作了一个可以与 fortunejs 配合使用的创建页面。为此,我必须像这样修改 RESTSerializer:

App.ApplicationSerializer = DS.RESTSerializer.extend({
serialize: (record, options) ->
    [this._super record, options] #Turn into array

serializeIntoHash: (hash, type, record, options) ->
    console.log type.typeKey
    type.typeKey = Ember.Inflector.inflector.pluralize type.typeKey #pluralize root key
    console.log type.typeKey
    console.log record
    result = this._super hash, type, record, options

});

但这应该与来自 api 的传入 JSON 无关。

知道哪里出了问题吗?

最佳答案

我知道这已经过时了,我不确定 Stack Overflow 对此的政策,但我一直在翻阅未回答的问题,看看我是否知道我头脑中的任何问题......

我认为这里的问题在于 findAll(在当前版本的 Ember Data 中不存在)是一种仅执行存储查找的方法。相当于当前版本 ( http://emberjs.com/api/data/classes/DS.Store.html#method_all ) 中的 store.all

您需要 store.find,它向后端服务器请求数据 (http://emberjs.com/api/data/classes/DS.Store.html#method_find)。

希望这可以帮助任何偶然发现这个问题的人......

关于javascript - "Assertion Failed: The response from a findAll must be an Array, not undefined",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22864299/

相关文章:

javascript - 提取元素内的所有有效 URL 字符串 (JavaScript)

php - "invisible"数据 HTML 标签

javascript - 具有重置功能的 Angular Directive(指令)

正则表达式

json - 亚马逊上嵌套堆栈中的参数

c# - 如何使用静态数据填充 View 模型

javascript - 如何从 ember.js Controller 单击按钮

json - 如何在 Clojure 中获取以字符串形式存储在数据库中的日期?

ember.js - Ember.js 中的 "Dynamic segment"?

ember.js - 无法使用 embre-simple-auth-token 访问 session 属性和 JWT 声明