2
클릭 수에 응답하고 싶은 텍스트가있는 SVG 캔버스가 있습니다. 아래의 코드는 작업이 이루어지고되지 않습니다 svg 요소 인 el에 백본 이벤트가 적용되었습니다.
var MyView = Backbone.View.extend({
tagName : "text",
events : {
"click" : "clickhandler"
},
initialize : function() {
this.centerX = this.options.centerX;
this.centerY = this.options.centerY;
this.svg = this.options.svg;
this.tagText = this.model.get("tag_name");
this.render();
},
clickhandler : function(event) {
console.log("I was clicked!"); //This is not firing on click
},
render : function() {
this.el = this.svg.text(this.centerX, this.centerY, this.tagText, {});
return this;
}
});
이
같은 다른보기의 렌더링 함수에서 호출되는 :container.svg({
onLoad : function(svg) {
for (var i = 1; i < that.relatedTags.length; i++) {
tagView = new MyView({
model : this.relatedTags.at(i),
centerX : 100,
centerY : 200,
svg : svg
});
}
container.append(tagView);
}
});
그것은 잘 나타나 나는이를 던져 for 루프의 끝에서 :
$(tagView.el).click(function() {
alert("xx");
});
그런 다음 딸깍 작품 그러나 나는보기와 관련된 백본 모델에 접근 할 필요가
그래서 많은 직선 JQuery와 이벤트에 백본 이벤트를 선호하는 것입니다.