M试着给 mouseover
在我看来Backbone的事件中,这是我的看法:
Backbone.View.extend({
template :_.template( '<li class="<% if (refertype=="U"){%>info <% }else{%> access<%}%> main"><%=refername%>'+
'</li>'),
initialize: function() {
_.bindAll(this, 'render', 'close');
this.model.bind('change', this.render);
this.model.view = this;
},
events: {
"mouseover .main": "mouseovercard"
},
// Re-render the contents of the Card item.
render: function() {
this.el=this.template(this.model.toJSON());
$(".cards-list").append(this.el);
},
mouseovercard: function() {
console.log("hello world");
}
});
但是,当我正在做鼠标时 main
它不显示的课程 hello world
,请建议做什么?
试过Heikki答案但鼠标悬停不起作用?
App.Backbone.CardView = Backbone.View.extend({
tagName: 'li',
className: 'main',
initialize: function() {
_.bindAll(this, 'render');
this.model.bind('change', this.render);
this.model.view = this;
},
events:{
"mouseover .main": "mouseovercard"
},
// Re-render the contents of the Card item.
render: function() {
$(this.el)
.removeClass('info access')
.addClass(this.model.get('refertype') == 'U' ? 'info' : 'access')
.text(this.model.get('refername'));
$(".cards-list").append(this.el);
},
mouseovercard: function() {
console.log("hello world");
}
});