【问题标题】:How to select child vertex in one click on mxgraph?如何在 mxgraph 上一键选择子顶点?
【发布时间】:2021-03-19 14:25:54
【问题描述】:

我有嵌套的顶点,我想在第一次点击子节点时选择子顶点。

现在,当我单击子顶点时,它首先选择父顶点。

首先选择父顶点:

为了选择子顶点,我必须再次单击子顶点。

双击后选中的子顶点:

如何在第一次点击时选择子顶点?

【问题讨论】:

    标签: javascript angular typescript mxgraph


    【解决方案1】:

    我通过重写 getInitialCellForEvent 函数解决了这个问题。

    mxGraphHandler.prototype.getInitialCellForEvent = function(me)
    {
        var state = me.getState();
        return (state != null) ? state.cell : null;
    };
    

    原来是这样的。我删除了检索最顶层单元格的 if 部分。

    /**
     * Function: getInitialCellForEvent
     * 
     * Hook to return initial cell for the given event. This returns
     * the topmost cell that is not a swimlane or is selected.
     */
    mxGraphHandler.prototype.getInitialCellForEvent = function(me)
    {
        var state = me.getState();
        
        if ((!this.graph.isToggleEvent(me.getEvent()) || !mxEvent.isAltDown(me.getEvent())) &&
            state != null && !this.graph.isCellSelected(state.cell))
        {
            var model = this.graph.model;
            var next = this.graph.view.getState(model.getParent(state.cell));
    
            while (next != null && !this.graph.isCellSelected(next.cell) &&
                (model.isVertex(next.cell) || model.isEdge(next.cell)) &&
                this.isPropagateSelectionCell(state.cell, true, me))
            {
                state = next;
                next = this.graph.view.getState(this.graph.getModel().getParent(state.cell));
            }
        }
        
        return (state != null) ? state.cell : null;
    };
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多