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

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

问题描述

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

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

我遵循了这里的建议..访问控制器函数内的内容 ember

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}

这也是我的代码..

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

这是我的模板代码

http://screencast.com/t/horNlooKx8l

任何反馈都将不胜感激

谢谢

推荐答案

你的问题是 https://torid-heat-7210.firebaseio.com/fixed_column.json 返回一个对象 ({}) 其中 {{#each}}helper 需要一个数组 ([]).

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

您可以如下修改您的 setupController 方法以使其工作:

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

工作解决方案这里

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

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