setting data from route to controller error in Emberjs(在 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 中设置从路由到控制器错误的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 Emberjs 中设置从路由到控制器错误的数据
基础教程推荐
- Javascript 在多个元素上单击事件侦听器并获取目标 2022-01-01
- 每次设置弹出窗口的焦点 2022-01-01
- 如何在特定日期之前获取消息? 2022-01-01
- 为什么我在 Vue.js 中得到 ERR_CONNECTION_TIMED_OUT? 2022-01-01
- WatchKit 支持 html 吗?有没有像 UIWebview 这样的控制器? 2022-01-01
- 什么是不使用 jQuery 的经验技术原因? 2022-01-01
- 如何使用 CSS 显示和隐藏 div? 2022-01-01
- 如何使用sencha Touch2在单页中显示列表和其他标签 2022-01-01
- jQuery File Upload - 如何识别所有文件何时上传 2022-01-01
- Node.js 有没有好的索引/搜索引擎? 2022-01-01
