Ember数据“断言失败:错误:断言失败:来自findAll的响应必须是数组,而不是未定义” [英] Ember-data "Assertion Failed: Error: Assertion Failed: The response from a findAll must be an Array, not undefined"

查看:92
本文介绍了Ember数据“断言失败:错误:断言失败:来自findAll的响应必须是数组,而不是未定义”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在这个问题上停留了很长时间了。我已经深入研究了stackoverflow中的问题,无法找到解决方案。



我正在尝试使用ember-data和rails API将JSON数据加载到我的应用商店。我正在使用ember-cli。



我继续得到的错误是:断言失败:错误:断言失败:findAll的响应必须是数组,而不是未定义



该应用程序由几个包含图表的报表组成。服务器触发对API的请求(以uuid作为查询字符串),并收到以下json响应:

  {
报告:$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ order order order order order order order order order order order order order order order order order order order order order order order order :0,
chart_ids:[
1
]
},
{
id:2,
name:Report 2
描述:测试报告2,
display_order:1,
chart_ids:[
5,
6
]
}
]
}

这是报告的路线:

 导出默认值Ember.Route.extend({
setupController:function(controller){
controller.set('model' this.store.find('report'));
}
});

我的模型:

  var Report = DS.Model.extend({
name:DS.attr('string'),
description:DS.attr('string'),
displayOrder:DS.attr('integer'),
图表:DS.hasMany('chart',{async:true})
});

var Chart = DS.Model.extend({
reports:DS.belongsTo('report'),
config:DS.attr()
}) ;我正在使用ActiveModelAdapter和ActiveModelSerializer:



ApplicationAdapter

 导出默认DS.ActiveModelAdapter.extend({
命名空间:'api',
ajax:function(url,type,hash){
if(Ember.isEmpty(hash)){
hash = {};
}

if(Ember.isEmpty(hash.data)){
hash.data = {};
}

hash.data.uuid = $。 cookie('uuid');
this._super(url,type,hash);
}
});

和序列化程序:

  export default DS.ActiveModelSerializer.extend(); 

我现在很沮丧。 Ember调试器不是很有帮助。任何帮助将被超级赞赏。



让我知道如果有更多的信息将会有帮助。

解决方案

我很确定这需要是 charts_ids 而不是 chart_ids (注意



或将您的hasMany更改为图表(虽然看起来很奇怪,但是在图表中的 s

  var Report = DS.Model.extend({
name:DS.attr('string'),
描述:DS.attr('string'),
displayOrder:DS.attr('integer'),
图表:DS.hasMany('chart',{async:true})
});

您没有返回ajax。

  App.ApplicationAdapter = DS.ActiveModelAdapter.extend({
namespace:'api',
ajax:function(url,type,hash){
if(Ember.isEmpty(hash)){
hash = {};
}

if(Ember.isEmpty(hash.data)){
hash .data = {};
}

hash.data.uuid = $ .cookie('uuid');
返回this._super(url,type,hash);
}
});

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


I have been stuck on this issue for quite awhile now. I have thoroughly researched the issue on stackoverflow and was unable to find a solution.

I am trying to load JSON data into my application store with ember-data and a rails API. I am using ember-cli.

The error I am continuing to get is: Assertion Failed: Error: Assertion Failed: The response from a findAll must be an Array, not undefined

The application consists of several reports that each have charts. The server fires off a request to the API (with a uuid tacked on as a query string) and receives the following json response:

{
    reports: [
        {
            id: 1,
            name: "Report 1",
            description: "Test Report 1",
            display_order: 0,
            chart_ids: [
                1
            ]
        },
        {
            id: 2,
            name: "Report 2",
            description: "Test Report 2",
            display_order: 1,
            chart_ids: [
                5,
                6
            ]
        }
    ]
}

This is the route for reports:

export default Ember.Route.extend({
    setupController: function(controller) {
         controller.set('model', this.store.find('report'));
    }
});

And my models:

var Report = DS.Model.extend({
    name: DS.attr('string'),
    description: DS.attr('string'),
    displayOrder: DS.attr('integer'),
    charts: DS.hasMany('chart', { async: true })
 });

var Chart = DS.Model.extend({
    reports: DS.belongsTo('report'),
    config: DS.attr()
});

I am using an ActiveModelAdapter and an ActiveModelSerializer:

ApplicationAdapter:

export default DS.ActiveModelAdapter.extend({
    namespace: 'api',
    ajax: function(url, type, hash) {
        if (Ember.isEmpty(hash)) {
            hash = {};
        }

        if (Ember.isEmpty(hash.data)) {
            hash.data = {};
        }

        hash.data.uuid = $.cookie('uuid');
        this._super(url, type, hash);
    }
});

And serializer:

export default DS.ActiveModelSerializer.extend();

I'm so frustrated at the moment. Ember debugger isn't being very helpful. Any help would be super appreciated.

Let me know if any more info would be helpful.

解决方案

I'm pretty sure this needs to be charts_ids instead of chart_ids (note the s after chart) in the JSON response for reports.

or change your hasMany to chart (though that seems weird)

 var Report = DS.Model.extend({
    name: DS.attr('string'),
    description: DS.attr('string'),
    displayOrder: DS.attr('integer'),
    chart: DS.hasMany('chart', { async: true })
 });

You're not returning the ajax.

App.ApplicationAdapter= DS.ActiveModelAdapter.extend({
  namespace: 'api',
    ajax: function(url, type, hash) {
        if (Ember.isEmpty(hash)) {
            hash = {};
        }

        if (Ember.isEmpty(hash.data)) {
            hash.data = {};
        }

        hash.data.uuid = $.cookie('uuid');
        return this._super(url, type, hash);
    }
});

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

这篇关于Ember数据“断言失败:错误:断言失败:来自findAll的响应必须是数组,而不是未定义”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆