javascript – ember.js错误:断言失败:来自findAll的响应必须是一个数组,而不是未定义

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

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密钥也应该是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

点赞