Backbone JS点击事件处理程序不工作

twh00eeo  于 2022-11-10  发布在  其他
关注(0)|答案(1)|浏览(91)

我试图将click事件处理程序添加到我的 Backbone javascript文件中。但是它显示了一个错误:“未捕获的类型错误:无法读取未定义的属性'html'。”以下是代码。如有任何帮助,将不胜感激。main.js文件

var Song = Backbone.Model.extend();

var SongView = Backbone.Model.extend({
events: {
    "click": "onClick",
    "click .bookmark": "onClickBookmark"
},
onClick: function(){
    console.log("Listen Clicked");
},

onClickBookmark: function(e){
    e.stopPropagation();

    console.log("Bookmark Clicked");
},

render: function(){
this.$el.html(this.model.get("title") + " <button>Listen</button> <button class='bookmark'> Bookmark</button>");

    return this;
}
 });

 var song = new Song({title: "sky is sdv sv"});

 var songView = new SongView({el: "#container", model: song});
 songView.render();
rhfm7lfc

rhfm7lfc1#

var SongView = Backbone.Model.extend({

应该是

var SongView = Backbone.View.extend({

相关问题