【问题标题】:ember.js Error: Assertion Failed: The response from a findAll must be an Array, not undefinedember.js 错误:断言失败:来自 findAll 的响应必须是数组,而不是未定义
【发布时间】:2014-03-21 22:31:34
【问题描述】:

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

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"}]}

【问题讨论】:

    标签: javascript ember.js


    【解决方案1】:

    完全合法的问题,

    你应该使用camelCase查询它:

    this.store.find('urlType')
    

    你的 json 键也应该是 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

    【讨论】:

    • 谢谢你,工作就像一个魅力!是否可以调试这样的问题,或者它的来源应该是“刚刚知道”?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-18
    • 1970-01-01
    • 2020-09-06
    • 2014-01-18
    • 2021-04-09
    • 2021-10-17
    相关资源
    最近更新 更多