Search code examples
extjsextjs3

How to change node in TreeMenu?


I have the TreeMenu with some nodes:

{
    text: 'Test',
    leaf: true
}

I attached a listener on the TreeMenu:

listeners: {
  contextmenu: function(node, event) {

    ContextMenu.showAt(event.getXY());
    event.stopEvent();

  }
}

But I don't know how to change the node:

// HTML don't changed
node.text = 'my value';

// Uncaught TypeError: node.reload is not a function
node.reload();

UPD

I decided in this way:

node.setText('my value');

Solution

  • The tree has to have some kind of store / root (NodeInterface). All you have to do is to change the value in the store / root and the tree will be automatically changed.

    You should never use node.text = 'my value' because in most cases it won't be just simple object. You should use node.set('text', 'My Text');

    The handler function for change could look something like this:

        handler: function() {
            var tree = Ext.ComponentQuery.query('treepanel')[0];
            var child = tree.getRootNode().getChildAt(0);
            child.set('text', 'Chaned text');
        }
    

    Check this fiddle: https://fiddle.sencha.com/#fiddle/1hc1

    I am not sure which exact version of ExtJS are you using? Ext 3 ? More or less the concept should be the same over all Ext versions.