在Emberjs中将数据从路由设置到控制器错误 [英] setting data from route to controller error in Emberjs

查看:153
本文介绍了在Emberjs中将数据从路由设置到控制器错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Emberjs中的新手。
我试图将数据内容从Emberjs路由设置到控制器以显示在模板中。



我跟随这里的建议..
访问控制器功能内的内容ember



完美的工作...但现在我收到这个错误

 未捕获错误:断言失败:#each循环的值必须是数组。您通过{items:[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],title:current mood} 

编辑:
这里也是我的代码..



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



这里是我的模板代码



http:// screencast.com/t/horNlooKx8l



任何反馈将不胜感激



谢谢

解决方案

您的问题是 https://torid-heat-7210.firebaseio.com/fixed_column.json 返回一个Object( {} )where as code> {{#each}} 帮助器期待一个数组( [] )。



您可以将 setupController 方法修改为接下来让它工作:

  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);
})
}

工作解决方案 here


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

解决方案

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

这篇关于在Emberjs中将数据从路由设置到控制器错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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