0

Addy OsmaniによるBackbone.jsアプリケーションの開発を学んでいて、行き詰まっています。

これが私の見解です:

var TodoView = Backbone.View.extend({
    tagName: 'li',
    className: 'todo_list',
    todoTpl: _.template($('#item-template').html()),
    events:{
        'dblclick label': 'edit',
        'keypress .edit':'updateOnEnter',
        'blur .edit':'closed'
    },
    initialize:function(){
        _.bindAll(this, 'edit','render','updateOnEnter','closed');
        this.render();
    },
    render: function(){
        this.$el.html(this.todoTpl(this.model.toJSON()));
        this.input = this.$('.edit');
        return this;
    },
    edit: function(){},
    updateOnEnter: function(){},
    closed: function(e){}
});

var todoView = new TodoView();
console.log(todoView.el);

そしてここに私のエラーがあります:

 TypeError: this.model is undefined
 this.$el.html(this.todoTpl(this.model.toJSON()));

私はどこが間違っていますか?

4

1 に答える 1

0

ビューにモデルを渡していないため、this.modelは未定義です

試す

var myModel  = // define your model
var todoView = new TodoView({
    model: myModel
});
于 2013-01-18T10:16:19.217 に答える