如何在联合JS中的克隆的联合元素上触发pointerdown/dragstart?
在工具箱纸张上触发toolBoxPointerDown事件时,会触发pointerdown
addNode上触发pointerup事件时,会触发_this.paperDrag

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,这两个函数的最后代码行使notify像这样:
this.notify('element:pointerdown', evt, x, y);
并在该通知产生后执行了paper.on('element:pointerdown')

10-04 22:03