2
我是Backbone的新手,尝试做一些示例,但我坚持使用这个示例。 我有以下骨干查看:骨干视图更改el属性时不会触发事件
CommentBoxView = Backbone.View.extend({
initialize: function() {
this.render();
},
render: function() {
var template = _.template($("#comment_box_template").html(), {});
this.el.html(template);
},
events: {
"keypress textarea": "doKeyPress"
},
doKeyPress: function (event) {
console.log(event);
}
});
一切都运行正常,但如果我更换
this.el.html(模板);
与此:
this.el = $(模板).replaceAll(this.el);
keypress事件根本没有被触发。 任何人都可以请向我解释为什么发生这种情况,以及如何使这段代码有效?非常感谢你。