abrejohn
abrejohn

Reputation: 11

how to append/insert a child based on the path value extjs

Ext.getCmp('treepanel-id').getSelectionModel().getSelection()[0].getPath('parent')

i am getting :

"//Grandparent/Parent1/leaf1"

i need to insert a leaf after the path Please help me out.

Upvotes: 0

Views: 123

Answers (1)

scebotari66
scebotari66

Reputation: 3480

There is no standard way to do this, but, from your question I see that you want to append a sibling node after the current selected node. As you already have a reference to the selected node, you can achieve this like so:

var selectedNode = Ext.getCmp('treepanel-id').getSelectionModel().getSelection()[0],
    parentOfSelectedNode = selectedNode.parentNode,
    selectedNodeIndex = parentOfSelectedNode.indexOf(selectedNode);

parentOfSelectedNode.insertChild(selectedNodeIndex + 1, {
    text: 'New sibling node',
    leaf: true
});

Upvotes: 1

Related Questions