我刚刚开始学习backbone.js。我在backbonetorials.com上学习本教程,但由于某些原因,我无法将其付诸实践。到目前为止,我得到的是:
var View = Backbone.View.extend({
el: $('.container'),
initialize: function() {
this.render();
},
render: function() {
var templ = _.template($('#template').html(), {});
this.el.html(templ);
},
events: {
"click button": "buttonClick"
},
buttonClick: function() {
alert('clicked!');
}
});
var view = new View();
上面的问题出在哪里?我几乎只是把教程复制/粘贴到小提琴上。它是否与正在使用的主干/下划线版本有关?
提前谢谢。
尝试
this.$el.html(templ);
而不是
this.el.html(templ);
http://jsfiddle.net/eykKL/4/