在 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);
})
}
工作解决方案这里
相关文章