微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何在mxgraph上一键选择子顶点?

如何解决如何在mxgraph上一键选择子顶点?

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

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

首先选择父顶点:

Parent vertex selected first

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

双击后选择的子顶点:

Child vertex selected after double click

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

解决方法

我通过覆盖 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;
};

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。