我知道如何处理一般事件,比如点击等,但是我在理解如何在我的渲染函数中监听函数触发的事件时遇到了问题:
function( ft, events) {
console.log(events);
}); /*fires ["drag start"]
["drag"]
["apply"]
["drag"]
["apply"]
["drag"]
etc.*/
现在我想在我的视图中有处理程序来监听这些事件。我该怎么做?
这是整个视图:
var myView = Backbone.View.extend({
initialize: function () {
self = this;
this.element = paper.rect();
this.setElement(this.element.node);
this.delegateEvents(this.events);
},
events: {
"click": "showHandles",
"drag end": "dragEndHandler"
},
dragEndHandler: function(e){
console.log('dragEnd');
},
showHandles: function(e){
this.ft.showHandles();
},
render: function(){
this.element.attr({
'x': this.model.get('x'),
'y': this.model.get('y'),
'width': this.model.get('width'),
'height': this.model.get('height'),
'fill': this.model.get('fill'),
'cursor': this.model.get('cursor')
})
// Add freeTransform with options and callback
this.ft = paper.freeTransform(this.element, {
'keepRatio': ['axisX', 'axisY'],
'size': 4,
//set handle
'attrs': {'fill': '#436eee', 'stroke': '#fff'}
},
function( ft, events) {
console.log(events);/*fires ["drag start"]
["drag"]
["apply"]
["drag"]
["apply"]
["drag"]
etc.*/
});
return this;
}
});