1
백본에 새 기능을 추가하고 백본을 배우기위한 간단한 응용 프로그램을 작성하려고합니다.백본보기가 예기치 않게 업데이트되었습니다.
응용 프로그램에는 항목 목록이 포함되어 있으며 사용자가 항목보기 중 하나를 가리키면 해당 항목의 색이 빨간색으로 바뀌고 그 색은 검은 색이어야합니다.
var ItemView = Backbone.View.extend({
tagName: 'li',
events: {
'click a.delete': 'onDelete',
'mouseover': 'onHoverIn',
'mouseout': 'onHoverOut'
},
template: _.template($('#tpl-item').html()),
initialize: function() {
this.model.on("change", this.render, this);
},
render: function() {
var item = this.model;
this.$el.css("color", item.get("hover") ? "red" : "black").html(this.template(item.toJSON()));
return this;
},
onDelete: function() {
this.model.destroy();
},
onHoverIn: function() {
this.model.set("hover", true);
},
onHoverOut: function() {
this.model.set("hover", false);
}
});
이 응용 프로그램의 전체 코드입니다 : 내가 빨리 이동하면 나는 천천히 하나 하나의 항목 위에 마우스를 이동하면서 그러나 jfiddle live example
, 내가 더있을 수 있음을 발견, 작동 하나 이상의 항목이 빨간색으로 표시되어 예상치 못한 결과를 초래합니다.
무슨 일이야?
이유는 안정적으로 mouseOut 이벤트를 캡처 할 수 없습니다 [의 중복 가능성? ] (http://stackoverflow.com/questions/7448468/why-cant-i-reliably-capture-a-mouseout-event) –
귀하의 링크를 가져 주셔서 감사하지만 일단 내가 그것을 확인 적절한 대답이 없다는 것을 발견했다. 심지어 mouseout/over 대신에 mouseenter를 사용하려고했습니다. – hguser