0
我有以下骨幹模型與d3.drag功能。我不能在d3的上下文中調用模型的this
。如何調用backbone.model的這個內部d3.drag上下文
我遇到類似問題的解決方案,通過定義變量model=this
和調用model.draw..
,但我怎麼能在d3的拖動中添加它?
DataMapper.Models.Anchor = Backbone.Model.extend({
defaults: {
//...
},
initialize : function(){
d3.select("#anchor").call(this.dragAnchor); //make the #anchor draggable
},
dragAnchor: d3.drag()
.on("start", function (d) {
console.log("something"); //it prints
var thisDragY = this.drawSomething(a,b,c);
// this.drawSomething is not a function
// because inside d3.drag(), 'this' refers to #anchor
// what I want to refer is the model
})
.on("drag", function (d) {})
.on("end", function (d) {}),
drawSomething: function (parent, cx, cy) {
//code
}
});
有沒有辦法使用下劃線的bind
來實現我想要的目標? Link to a useful article。