How to give JointJS elements a remove tool?

前端 未结 4 1715
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-09 06:53

In JointJS, links come with a handy responsive tool for removing links (when you hover over the link, an \"x\" appears, and clicking it removes the link). Elements, on the

4条回答
  •  Happy的楠姐
    2020-12-09 07:51

    joint.shapes.devs.ModelView = joint.dia.ElementView.extend(_.extend({},joint.shapes.basic.PortsViewInterface,{
             initialize:function(){
             joint.dia.ElementView.prototype.initialize.apply(this,arguments);
     },
        render:function(){
                joint.dia.ElementView.prototype.render.apply(this,arguments);
                this.renderTools();
                this.update();
                return this;
    },
        renderTools:function(){
             var toolMarkup = this.model.toolMarkup || this.model.get('toolMarkup');
    
              if (toolMarkup) {
    
                 var nodes = V(toolMarkup);
                 V(this.el).append(nodes);
    
        }
    
        return this;
    },
        pointerclick: function (evt, x, y) {
            var className = evt.target.parentNode.getAttribute('class');
            switch (className) {
    
                case 'element-tool-remove':
                this.model.remove();
                return;
                break;
    
                default:
        }
    
         joint.dia.CellView.prototype.pointerclick.apply(this, arguments);
    }
    

    }));

提交回复
热议问题