javascriptmxgraphjgraph

How to get parent cell from child cell in mxgraph


I want to remove all connected edges to the source from parent, so is there any function that can remove all edges connected from parent to child referring by the cell.

How to get parent cell from child cell in mxgraph.

I am trying to achieve drag and drop using connectors and am i correct?

mxConnectionHandler.prototype.connect = function(source, target, evt, dropTarget){
   // First I'll connect the target and source edges
   // Later I'll remove all connected edges from parent to source
}

source.parent.getValue('value') is undefined now.

I need parent references so that it helps in saving to database as well.

I can see this: mxCell.prototype.getParent = function() from documentation, but how to use this? Please demonstrate with a small example.

Tried using cell.getParent()

Also: graph.model.getParent(cell)

But it returns: mxCell {value: undefined, geometry: undefined, style: undefined, parent: mxCell, id: "1", …}

And its value as undefined. What am I doing wrong or how to perfectly get its parent cell reference?

The only way I got this worked by appending parentid to cellid. And use array split and get cell from its id, but I am not happy doing this as I will have a lot of work when multiple edges are connected. So, I need the simplest solution.


Solution

  • Gave up the thought of debugging under: graph.model.getParent(cell)

    The parent refers to the region and its shared with all the vertexes. Hence, came across the parent cell reference with the help of: cell.edges[0].source for single edge connection, if there are multiple edges connected from different parents, it should be cell.edges[...n].source upto you how you want to address them.