Javascript 值#每个循环必须是一个数组,控制器传递
我在加载页面时收到以下错误消息:Javascript 值#每个循环必须是一个数组,控制器传递,javascript,ember.js,Javascript,Ember.js,我在加载页面时收到以下错误消息: Assertion failed: The value that #each loops over must be an Array. You passed (generated snippets.index controller) ember-1.0.0.js:394 Uncaught TypeError: Object [object Object] has no method 'addArrayObserver' 以下是我的模板代码: <
Assertion failed: The value that #each loops over must be an Array.
You passed (generated snippets.index controller) ember-1.0.0.js:394
Uncaught TypeError: Object [object Object] has no method 'addArrayObserver'
以下是我的模板代码:
<script type="text/x-handlebars" data-template-name="snippets/index">
{{#each}}
{{title}}
{{/each}}
</script>
我的应用程序和我的路由器:
window.TSLibrary = Ember.Application.create();
TSLibrary.ApplicationAdapter = DS.FixtureAdapter.extend();
// ---
TSLibrary.Router.map(function () {
this.resource('snippets', { path: '/' }, function () {
});
});
TSLibrary.SnippetsRoute = Ember.Route.extend({
model: function () {
// My guess is that this does not return the expected array
//
// This logs 'Class {toString: function, constructor: function, reason: null, isPending: undefined, isSettled: undefined…}'
console.log(this.store.find('snippet'));
return this.store.find('snippet');
}
});
所以我猜this.store.find('snippet')
没有返回正确的数据。
我还在Chrome中安装了Ember调试扩展,它向我显示了模型中所有正确的数据
余烬版本:1.0.0余烬数据版本:
v1.0.0-beta.1-140-ga51f29c a51f29c(2013-09-07 16:34:55-0700)
车把版本:1.0.0
jQuery版本:1.10.2
我偶然发现了解决方案,现在:
TSLibrary.Router.map(function () {
this.resource('snippets', { path: '/' }, function () {
});
});
一定是
TSLibrary.Router.map(function () {
this.resource('snippets', { path: '/' });
});
这样就创建了“snippets.index”路径,它需要一个名为SnippetsIndexRoute的路由
TSLibrary.Router.map(function () {
this.resource('snippets', { path: '/' });
});
这只是“代码片段”,它正确地使用了您定义的SnippetsRoute。我又遇到了我自己的问题。看来我没有收到你的帖子的通知。无论如何,欢迎来到StackOverflow,并得到您的第一个接受答案:)谢谢。有了这个问题,只需在我的驼峰式路由名称中添加“Index”一词即可。谢谢
TSLibrary.Router.map(function () {
this.resource('snippets', { path: '/' }, function () {
});
});
TSLibrary.Router.map(function () {
this.resource('snippets', { path: '/' });
});