Ember待办事项:Ember.CollectionView的内容必须实现Ember.Array [英] Ember todos: an Ember.CollectionView's content must implement Ember.Array

查看:119
本文介绍了Ember待办事项:Ember.CollectionView的内容必须实现Ember.Array的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在努力让自己了解Ember,并阅读待办事项教程。我在这里停留在display-model-data步骤
http: //emberjs.com/guides/getting-started/displaying-model-data/

I'm trying to get my head around Ember and going through the todos tutorial. I get stuck on the displaying-model-data step here http://emberjs.com/guides/getting-started/displaying-model-data/

这是我从本教程复制并粘贴的JavaScript:

here's the javascript i copied and pasted from the tutorial:

window.Todos = Ember.Application.create();

Todos.Router.map(function () {
  this.resource('todos', { path: '/' });
});

Todos.TodosRoute = Ember.Route.extend({
  model: function () {
    return Todos.Todo.find();
  }
});

Todos.Store = DS.Store.extend({
  revision: 12,
  adapter: 'DS.FixtureAdapter'
});

Todos.Todo = DS.Model.extend({
  title: DS.attr('string'),
  isCompleted: DS.attr('boolean')
});

Todos.Todo.FIXTURES = [
  {
    id: 1,
    title: 'Learn Ember.js',
    isCompleted: true
  },
  {
    id: 2,
    title: '...',
    isCompleted: false
  },
  {
    id: 3,
    title: 'Profit!',
    isCompleted: false
  }
];

然后这是我的车把模板:

Then here's my handlebars template:

...
          {{#each controller}}
            <li>
              <input type="checkbox" class="toggle">
              <label>{{title}}</label><button class="destroy"></button>
            </li>
          {{/each}}

但是我收到此错误

Uncaught Error: assertion failed: an Ember.CollectionView's content must implement Ember.Array. You passed <(generated todos controller):ember257> 

在我看来,Ember生成的任何默认控制器对象都应为Ember.Array类型,但它是由于某种原因没有发生。我想知道ember-data是否有问题?

It looks to me like whatever default controller object Ember generates should be of type Ember.Array but it is not happening for some reason. I am wondering if it is a problem with ember-data?

我正在使用入门工具包中的所有文件,即
ember 1.0.0 rc5
handlebars 1.0.0 rc4
jquery 1.9.1
和ember-data,我唯一能知道的版本指示来自注释

I am using all the files from the starter kit which are ember 1.0.0 rc5 handlebars 1.0.0 rc4 jquery 1.9.1 and ember-data, the only versioning indication i can tell is from a comment

// Last commit: 3981a7c (2013-05-28 05:00:14 -0700)

有人知道某个依赖项问题,或者我做错了什么?

Is there a dependency problem someone knows about or did I do something wrong?

推荐答案

我不会说这是ember数据的问题,因为该模块仅负责与api对话并为您提供聪明的模型对象。

I wouldn't say its a problem with ember data, since that module is responsible only for talking to the api and giving you clever model objects.

您说的是ember是正确的生成错误类型的控制器。默认情况下,当您需要的是 ArrayController 时,Ember可能会生成一个 Controller 。要解决该问题,只需创建一个像这样的空控制器

You were right in saying ember is generating the wrong type of controller. By default Ember will probably generate a Controller, when what you need is an ArrayController. To get around the issue, simply create an empty controller like this

Todo.TodosController = Em.ArrayController.extend({});

指南确实指出,余烬会创建 ArrayController ,但也许不再了!?让我知道它是否可以通过显式创建一个arraycontroller来工作。如果可以,我们可以通知余烬小组。

The guide does say that ember creates an ArrayController, but perhaps it doesn't anymore!? let me know if it works by explicitly creating an arraycontroller. If it does we can let the ember team know.

这篇关于Ember待办事项:Ember.CollectionView的内容必须实现Ember.Array的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆