javascript - ember.js 错误 : Assertion Failed: The response from a findAll must be an Array, 未定义

标签 javascript ember.js

也许这是有史以来最愚蠢的问题,但仍然是 - 如何手动查询服务器以获取特定模型的记录?

App.UrlNewRoute = Ember.Route.extend({
  setupController: function(controller, model) {
    console.dir(1);
    this.store.find('UrlType').then(function(url_types) {
      controller.set('urlTypes',url_types);
    });
  }
});    

{"url_types":[{"id":1,"caption":"text link"},{"id":2,"caption":"guest post"},{"id":3,"caption":"blog comment"},{"id":4,"caption":"banner"},{"id":5,"caption":"profile"},{"id":6,"caption":"review"}]}

最佳答案

完全合理的问题,

您应该使用 camelCase 查询它:

this.store.find('urlType')

并且您的 json key 也应该是 camelCase(您也可以使用序列化程序来修复它):

{
   "urlTypes":[
      {
         "id":1,
         "caption":"text link"
      },
      {
         "id":2,
         "caption":"guest post"
      },
      {
         "id":3,
         "caption":"blog comment"
      },
      {
         "id":4,
         "caption":"banner"
      },
      {
         "id":5,
         "caption":"profile"
      },
      {
         "id":6,
         "caption":"review"
      }
   ]
}

http://emberjs.jsbin.com/OxIDiVU/301/edit

关于javascript - ember.js 错误 : Assertion Failed: The response from a findAll must be an Array, 未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22560929/

相关文章:

Javascript 错误的日期格式

javascript - 如何覆盖 Ember 插件中的默认功能

javascript - 项目模态界面

javascript - 连接丢失时适配器错误

javascript - 为什么不能在普通函数或全局范围内使用await

javascript - vuejs 2 中可以合并数据根或更改整个数据状态吗

javascript - Bootstrap 可折叠面板内容重置为顶部

javascript - 如何将ajax响应转换为html

javascript - Ember 库导致 "Binding Style Attributes"弃用警告

javascript - EmberJS - 从 Controller 检索模型的奇怪行为