联合.js触发 拖动 开始于新的克隆元素



如何在关节 js 中触发克隆的关节元素上的指针/拖动启动? 在工具箱纸上触发pointerdown事件时会触发toolBoxPointerDown。 当_this.paperDrag上触发pointerup事件时会触发addNode

var toolBoxPointerDown = function(cell, event) {
        _this.action = 'addNode';
        $(document.body).append(_this.paperDrag.$el); 
        _this.clone = cell.model.clone(), _this.cloneBbox = cell.getBBox();
        _this.clone.set("position", {
            x: cell.model.attributes.position.x,
            y: cell.model.attributes.position.y 
        }), _this.paperDrag.addCell(_this.clone), _this.paperDrag.setDimensions("100%", "100%");
        _this.paperDrag.$el.offset({
            left: 0,
            top: 0
        });
        _this.paperDrag.findViewByModel(_this.clone.id).pointerdown();
    }
    var addNode = function(node, position) {
        var celltoAdd = _this.clone.clone();
        celltoAdd.set('position', { x: _this.clone.get('position').x - $('.toolbox').width(), y: _this.clone.get('position').y });

        if(celltoAdd.attributes.position.x > - 50){
            renderNode(celltoAdd.attributes);
        }
         _this.paperDrag.$el.detach();
        _this.clone.remove();
        _this.action = 'nodeAdded';
    }

以下代码添加到您的造纸工具中:

_this.paperDrag.on('element:pointerup', this.addNode , this);
_this.paperDrag.on('element:pointerdown', this.toolBoxPointerDown , this);

一些解释:joint.dia.ElementView内置了 pointerdown 和 pointerup,这两个函数的最后一行代码使通知如下:

this.notify('element:pointerdown', evt, x, y);

并且您的paper.on('element:pointerdown')将在该通知产生后执行。