setting data from route to controller error in Emberjs

醉酒当歌 提交于 2019-12-13 02:33:30

问题


i am a newbie in Emberjs.. I am trying to set data content from Emberjs route to controller to display in template..

i followed the suggestions here.. Access content inside a controller function ember

works perfect.. but now i am getting this error

Uncaught Error: Assertion Failed: The value that #each loops over must be an Array. You passed {items: [object Object],[object Object],[object Object],[object Object],[object Object],[object Object], title: current mood}

edit: here is also my code..

http://screencast.com/t/4fXm5n5u9lpH

and here is my template code

http://screencast.com/t/horNlooKx8l

any feedback would be appreciated

thanks


回答1:


Your problem is that https://torid-heat-7210.firebaseio.com/fixed_column.json returns an Object ({}) where as {{#each}} helper is expecting an array ([]).

You can modify your setupController method as follows to get it to work:

setupController: function(controller){
  Ember.$.ajax({
    url: 'https://torid-heat-7210.firebaseio.com/fixed_column.json',
    type: 'GET'
  }).done(function(data){
    controller.set('content', data.items);
  })
}

Working solution here



来源:https://stackoverflow.com/questions/28680572/setting-data-from-route-to-controller-error-in-emberjs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!