我在加载页面时收到以下错误消息:
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>
我的&#39;代码段&#39;模型很简单:
TSLibrary.Snippet = DS.Model.extend({
title: DS.attr('string')
});
TSLibrary.Snippet.FIXTURES = [{id: 1, title: 'Learn Ember.js'}];
我的应用和我的路由器:
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调试扩展程序,它在我的模型中显示了所有正确的数据。
Ember版本:1.0.0
Ember数据版本:v1.0.0-beta.1-140-ga51f29c a51f29c (2013-09-07 16:34:55 -0700)
把手版本:1.0.0
jQuery版本:1.10.2
答案 0 :(得分:5)
TSLibrary.Router.map(function () {
this.resource('snippets', { path: '/' }, function () {
});
});
这种方式会创建'snippets.index'路径,这需要一个名为SnippetsIndexRoute的路径。
TSLibrary.Router.map(function () {
this.resource('snippets', { path: '/' });
});
这个只是'片段',它正确使用您定义的SnippetsRoute。
答案 1 :(得分:0)
我偶然找到了解决方案,现在:
TSLibrary.Router.map(function () {
this.resource('snippets', { path: '/' }, function () {
});
});
必须是
TSLibrary.Router.map(function () {
this.resource('snippets', { path: '/' });
});