单击时无法检索形状的mxcell值

时间:2019-10-15 06:55:10

标签: javascript xml mxgraph

我有一个mxWindow,其中创建了一个图形并在其中添加了形状。单击形状时,我想检索它的mxcell值。

我在下面附加了我的代码。除此之外,我尝试使用

graph.getModel() 
graph.getSelectionCell()

但是他们都没有给出期望的输出。

 var tb = document.createElement('div');
        var wnd = new mxWindow('Title', tb, 240, 240, 200, 200, true, true);
        wnd.setMaximizable(true);
        wnd.setResizable(true);
        wnd.setVisible(true);
        wnd.setClosable(true);
        var graphs = new mxGraph(tb);
        graphs.setTooltips(true);
        graphs.setPanning(true);
        graphs.setEnabled(false)
        var rubberband = new mxRubberband(graphs);
        new mxKeyHandler(graphs);
        mxEvent.disableContextMenu(tb);
        var parent = graphs.getDefaultParent();
        var v1,v2,v3,v4,v5,v6,v7,v8,v9
        graphs.getModel().beginUpdate();
       try
                {
                    v1 = graphs.insertVertex(parent, Editor.guid(), null , 20, 20, 50, 50, "shape=mxgraph.bpmn.shape;html=1;verticalLabelPosition=bottom;labelBackgroundColor=#ffffff;verticalAlign=top;align=center;perimeter=ellipsePerimeter;outlineConnect=0;outline=standard;symbol=general;");
                    v2 = graphs.insertVertex(parent, Editor.guid(), null , 80, 20, 50, 50, "shape=mxgraph.bpmn.shape;html=1;verticalLabelPosition=bottom;labelBackgroundColor=#ffffff;verticalAlign=top;align=center;perimeter=ellipsePerimeter;outlineConnect=0;outline=throwing;symbol=general;");
                    v3 = graphs.insertVertex(parent, Editor.guid(), null, 140, 20, 50,50, "shape=mxgraph.bpmn.shape;html=1;verticalLabelPosition=bottom;labelBackgroundColor=#ffffff;verticalAlign=top;align=center;perimeter=ellipsePerimeter;outlineConnect=0;outline=end;symbol=general;")
                    v4 = graphs.insertVertex(parent, Editor.guid(), null, 20, 80, 50,50, "shape=ext;rounded=1;html=1;whiteSpace=wrap;")
                    v5 = graphs.insertVertex(parent, Editor.guid(), null, 80, 80, 50,50, "shape=ext;rounded=1;html=1;whiteSpace=wrap;dashed=1;dashPattern=1 4;")
                    v6 = graphs.insertVertex(parent, Editor.guid(), null, 140, 80, 50,50, "html=1;whiteSpace=wrap;rounded=1;")
                    v7 = graphs.insertVertex(parent, Editor.guid(), null, 20, 140, 50,50, "html=1;shape=plus;outlineConnect=0;")
                    v8 = graphs.insertVertex(parent, Editor.guid(), null, 80, 140, 50,50, "shape=note;whiteSpace=wrap;size=16;html=1;")
                    v9 = graphs.insertVertex(parent, Editor.guid(), null, 140, 140, 50,50, "shape=mxgraph.bpmn.shape;html=1;verticalLabelPosition=bottom;labelBackgroundColor=#ffffff;verticalAlign=top;align=center;perimeter=rhombusPerimeter;background=gateway;outlineConnect=0;outline=none;symbol=general;")
                }
                finally
                {
                    // Updates the display
                    graphs.getModel().endUpdate();
                }
              graphs.addListener(mxEvent.CLICK, function(sender, evt)
                {
                    var cell = evt.getProperty('cell');
                    if(cell != null){
                        var th = graphs.mxCell.getStyle()
                    }                        
                    mxUtils.alert('click: '+((cell != null) ? th : 'Graph'));
                    evt.consume();
                });

我希望结果是单击形状时创建一个变量xx,并将形状mxcell值存储在其中。

0 个答案:

没有答案