Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ember.js/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ember.js ArrayProxy需要一个数组或Ember.ArrayProxy,但您传递了一个对象_Ember.js_Ember Data_Active Model Serializers - Fatal编程技术网

Ember.js ArrayProxy需要一个数组或Ember.ArrayProxy,但您传递了一个对象

Ember.js ArrayProxy需要一个数组或Ember.ArrayProxy,但您传递了一个对象,ember.js,ember-data,active-model-serializers,Ember.js,Ember Data,Active Model Serializers,我得到这个错误: ArrayProxy expects an Array or Ember.ArrayProxy, but you passed object 我使用活动模型序列化程序从rails应用程序获取数据。数据显示在mhy ember inspector中,但我的模板未在控制台中正确呈现此错误 Router.map(function() { this.resource('brands', function() { this.resource('brand', { path:

我得到这个错误:

ArrayProxy expects an Array or Ember.ArrayProxy, but you passed object
我使用活动模型序列化程序从rails应用程序获取数据。数据显示在mhy ember inspector中,但我的模板未在控制台中正确呈现此错误

Router.map(function() {
  this.resource('brands', function() {
    this.resource('brand', { path: '/:brand_id' });
  });

  this.resource('campaigns', function() {
    this.resource('campaign', { path: '/:campaign_id' },
    this.resource('index'), { path: 'brands/:brand_id' });
  });
});

export default Ember.Route.extend({
  model: function() {
    return Ember.RSVP.hash({
      brand: this.store.find('brand'),
      campaign: this.store.find('campaign') 
    });
  }
});

export default DS.Model.extend({
  name: DS.attr('string'),
  facebook_page_id: DS.attr('string'),
  active: DS.attr('boolean'),
  facebook_uid: DS.attr('string'),
  facebook_token: DS.attr('string'),
  facebook_token_expires: DS.attr('string'),
  website_url: DS.attr('string'),
  privacy_policy_link: DS.attr('string'),
  terms_link: DS.attr('string'),
  instagram_account: DS.attr('string'),
  instagram_url: DS.attr('string'),
  twitter_account: DS.attr('string'),
  twitter_url: DS.attr('string'),
  avatar_url: DS.attr('string'),
  youtube_account: DS.attr('string'),
  youtube_url: DS.attr('string'),
  favicon_url: DS.attr('string'),
  open_graph_url: DS.attr('string'),
  campaigns: DS.hasMany('campaign', {async: true})
});

export default DS.Model.extend({
  name: DS.attr('string'),
  brand_id: DS.attr('string'),
  brand: DS.belongsTo('brand', {async: true})
});

{{#each brand in controller}}
  <a>
    {{#link-to 'brand' this}}
       {{brand.name}} 
     {{/link-to}}
   </a>
{{else}}
   <a>No brands found.</a>
{{/each}}
Router.map(函数(){
这个。资源('brands',函数(){
资源('brand',{path:'/:brand_id'});
});
此.resource('活动',函数()){
此.resource('campaign',{path:'/:campaign_id'},
this.resource('index'),{path:'brands/:brand_id'});
});
});
导出默认的Ember.Route.extend({
模型:函数(){
返回Ember.RSVP.hash({
品牌:this.store.find('brand'),
活动:this.store.find('活动')
});
}
});
导出默认DS.Model.extend({
名称:DS.attr('string'),
facebook\u page\u id:DS.attr('string'),
活动:DS.attr('boolean'),
facebook\u uid:DS.attr('string'),
facebook_令牌:DS.attr('string'),
facebook\u令牌\u过期:DS.attr('string'),
网站地址:DS.attr('string'),
隐私政策链接:DS.attr('string'),
术语链接:DS.attr('string'),
instagram_帐户:DS.attr('string'),
instagram_url:DS.attr('string'),
twitter_帐户:DS.attr('string'),
twitter_url:DS.attr('string'),
化身url:DS.attr('string'),
youtube_帐户:DS.attr('string'),
youtube_url:DS.attr('string'),
favicon_url:DS.attr('string'),
打开\u图形\u url:DS.attr('string'),
活动:DS.hasMany('campaign',{async:true})
});
导出默认DS.Model.extend({
名称:DS.attr('string'),
品牌标识:DS.attr('string'),
brand:DS.belongsTo('brand',{async:true})
});
{{{控制器中的每个品牌}
{{{#链接到“品牌”这个}
{{brand.name}
{{/链接到}
{{else}
没有找到品牌。
{{/每个}}

服务器日志中没有错误。

余烬默认索引控制器是
ArrayController
,它们希望自己的模型是一个数组。 在您的BrandsIndexRoute的模型钩子中,您将模型指定为

Ember.RSVP.hash({
  brand: this.store.find('brand'),
  campaign: this.store.find('campaign') 
});
它返回一个
单个对象
,而不是预期的
品牌数组。
你应该做的是:

//brands route
export default Ember.Route.extend({
  model: function() {
    return this.store.find('brand');
  }
});

//campaigns route
export default Ember.Route.extend({
  model: function() {
    return this.store.find('campaign');
  }
});

您试图在控制器上迭代,但控制器正在用两个属性装饰对象,而不是数组。您的对象如下所示:

{
  brand: [...],
  campaign: [...]
}

此外,如果您将控制器定义为数组控制器,它将抛出此错误(我猜这就是实际发生的情况)。因为您正在向控制器传递一个对象,而不是数组。

没有路由默认为任何特定的控制器类型,如果没有指定控制器类型,它将根据从模型挂钩返回的数据类型预测控制器类型。这是我最初做的,我想在同一个模板上查看数据。谢谢我们的帮助。当我使用一个对象控制器时,错误读到它需要一个数组和ArrayController?你的意思是说每个控制器需要一个数组?