Backbone JS 单击事件处理程序不起作用
Backbone JS Click Event Handlers does not work
我试图将点击事件处理程序添加到我的 backbone javascript 文件中。但它显示错误:"Uncaught TypeError: Cannot read property 'html' of undefined."
这是代码。任何帮助,将不胜感激。
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();
var SongView = Backbone.Model.extend({
应该是
var SongView = Backbone.View.extend({
我试图将点击事件处理程序添加到我的 backbone javascript 文件中。但它显示错误:"Uncaught TypeError: Cannot read property 'html' of undefined." 这是代码。任何帮助,将不胜感激。 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();
var SongView = Backbone.Model.extend({
应该是
var SongView = Backbone.View.extend({