我在加载页面时收到这些错误消息:
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>
我的“片段”模型非常简单:
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)
Handlebars 版本:1.0.0
jQuery 版本:1.10.2