dimanche 24 mai 2015

Assertion Failed: The value that #each loops over must be an Array error. What am I doing wrong?

I am following Ember's TodoMVC tutorial and I am stuck. Basically, I defined 2 controllers. This is todos.js

import Ember from "ember";

export default Ember.ArrayController.extend({
    actions:{
        createTodo: function(){
            var title = this.get("newTitle");

            if(!title){
                return false;
            }
            if(!title.trim()){
                return;
            }

            var todo = this.store.createRecord("todo", {
                title: title,
                isCompleted: false
            });

            // Clear text field
            this.set('newTitle', '');

            todo.save();
        }
    }
})

This is todo.js

import Ember from "ember"

export default Ember.ObjectController.extend({
    isCompleted: function(key, value){
        var model = this.get("model");

        if(value === undefined){
            return model.get("isCompleted");
        } else {
            model.set('isCompleted', value);
            model.save();
            return value;
        }
    }.property('model','model.isCompleted')
});

Finally, also defined todos.hbs

<ul id="todo-list">
    {{#each todo in model itemController="todo"}}
        <li {{bind-attr class="todo.isCompleted:completed"}}>
            {{input 
            type="checkbox"
            class="toggle"
            checked=todo.isCompleted
            }}
            <label>{{todo.title}}</label><button class="destroy"></button>
        </li>
    {{/each}}
</ul>

Everything looks good, but I am getting the following error in the console:

Uncaught Error: Assertion Failed: The value that #each loops over must be an Array. You passed todomvc-embercli@controller:array:, but it should have been an ArrayController

What am I doing wrong here?




Aucun commentaire:

Enregistrer un commentaire