How to reload Ext.tree.TreePanel on demand?

后端 未结 1 1691
慢半拍i
慢半拍i 2021-02-06 09:38

I want to create Ext.tree.TreePanel component and periodically load content from the external URl. So I\'ve written something like

 new Ext.tree.TreePanel({
             


        
相关标签:
1条回答
  • 2021-02-06 10:30

    What you're looking for is the load method for the TreeLoader. So something like this should work given your example.

    tree.getLoader().load(tree.root);
    

    Here's my full example that's available on my demo site as well. It's a little contrived and hacked together from one of the ExtJS demo's but it should get you what you need.

    Ext.onReady(function() {
        var root = new Ext.tree.AsyncTreeNode({
            text: 'Ext JS',
            id: 'src'
        });
        var reloadTree = function() {
            tree.enable();
            tree.getLoader().dataUrl = 'get-nodes2.php';
            tree.getLoader().load(tree.root);
        };
    
        var tree = new Ext.tree.TreePanel({
            animate: true,
            autoScroll: true,
            nodeType: 'async',
            loader: new Ext.tree.TreeLoader(),
            containerScroll: true,
            border: false,
            disabled: true,
            id: 'myTree'
        });
    
        var myPanel = new Ext.Panel({
            items: tree,
            border: false,
            tbar: [{
                text: 'Refresh',
                handler: reloadTree
            }]
        });
    
        tree.setRootNode(root);
        myPanel.render('tree');
    });
    

    Cheers

    0 讨论(0)
提交回复
热议问题