GOJS TREE with two groups with same key name

Hello I am implementing concepts of records containing tree.

so I am creating two groups in node Data Array

{ isGroup: true, key: -2, text: “Device Model”, xy: “300 0” },
{isGroup:true,key:-3,text:“test”,xy:“626 50”}

{isGroup:true,key:-3,text:“test”,xy:“626 50”}

and the text is binded to key

$(go.TextBlock,
new go.Binding(“text”, “key”, function(s) { return s; }))

now my problem is when ever i use the same key name and push it to the linkDataArray although they are in different groups. My tree link breaks up .

is there a way to differentiate linkDataArray.push with groups ?

Whenever you add two node data objects to a Model that have the same key value, the model will change the key to make them unique within the model.

If you had a link that referred to a node with the key of -3, which node/group should it refer to? It cannot refer to both at the same time (for the same end of the link). As a practical matter, in GoJS it would refer to the node/group that still had the key value remaining -3, and the other one (whose key value was changed to make it unique) would be not be referenced by that link.

Thanks for the response walter. I implemented an work around to bind a new variable called data to text instead of key and it works as i expected.

Thanks a lot though!

Thanks for the response walter. I implemented an work around to bind a new variable called data to text instead of key and it works as i expected.

Sorry to bump this old thread up, but @nadeemparvez.ak can you explain your solution a bit more, or perhaps share a code snippet of what you did? I am in the same situation, whereby I will legitimately have several child entries in the tree with the same name (but different parents). Thanks, mate!

Cheers.

Never mind, I figured it out! Always … as soon as you ask for help, the solution comes to you lol. For future reference by others:

var treeNodeDataArray = [

    { key: 'Parent Node 1', data: 'Parent Node 1' },
    { key: 'Node Name Here', parent: 'Parent Node 1', data: 'Node Name Here' },
     ...
    { key: 'Parent Node 2', data: 'Parent Node 2' },
    { key: 'Node Name Here', parent: 'Parent Node 2', data: 'Node Name Here' },
    ...
 ]

And then in the nodeTemplate for the tree view:

     $(go.TextBlock,
        { font: '9pt Verdana, sans-serif' },
        //new go.Binding("text", "key", function(s) { return s; }),
        new go.Binding("text", "data", function(s) { return s; })
     )

Cheers.

1 Like