ExtJs更改树根

Helo :)

I have a TreePanel (with a Button in its toolbar) with AsyncNode root. For some reason I need to change tree content when Button is clicked. I call Ext.Ajax.request and it returns all necessary data. But how can I put it into my TreePanel?

I tried following code, but it doesn't work :(

    Ext.Ajax.request({
        url: '../mocksearch',
        params: {
            pattern: txtSearch.getValue()
        },
        success: function(result, options) {
            searchResultRoot = Ext.decode(result.responseText);
            tree.setRootNode(searchResultRoot);                 
        }
    });

Your TreePanel is bound to a TreeLoader which is responsible of loading and holding the data.

Thus, the only way to change your Tree is to change the data in the TreeLoader.

You can try this : On your button, change the dataUrl and/or baseParams and call the Treeloader load method. Once loaded, the Treeloader should automagically refresh your tree.

You could try something like :

mybutton.on('click', function(button, event) {
     var treepanel = this.mytree;
     treepanel.dataUrl = 'mynewurl.php';
     treepanel.baseParams = {page:'tree2'}
     treepanel.getLoader.load( this.mytree.getRootNode() )
}, this);