Extjs 4 treepanel重新加载和展开

时间:2012-02-16 09:57:34

标签: extjs tree load extjs4

我正在使用带有Json数据的Extjs4 treepanel。我想重新加载treepanel并需要将树菜单扩展到指定的节点。 我正在使用以下代码。请告诉我这是怎么回事。

//Define tree store

var store = Ext.create('Ext.data.TreeStore', {
    proxy: {
        type: 'ajax',
        url: 'my_tree.php',
    },

    noCache: false
});

// Treepanel
var treePanel = Ext.create('Ext.tree.Panel', {
    id: 'mytree',
    renderTo: 'tree_div',
    height: 400,
    bodyBorder: false,
    border: false,
    singleExpand: true,
    rootVisible: false,
    store: store,
    useArrows: true
});

//Reload tree
    function reload_tree(){
       var tree_panel = Ext.getCmp('mytree');
        tree_panel.enable();
        tree_panel.getLoader().dataUrl = 'my_tree.php';
       tree_panel.getLoader().load(tree_panel.root);
       //Expand tree node
       tree_panel.getLoader().on('load', function(loader, node){ 
              tree_panel.getNodeById(nodeid).expand();
    //here node id is tree menu nodeid 
   });
   } 

提前致谢

1 个答案:

答案 0 :(得分:6)

重新加载树我觉得调用

更简单
treePanel.getStore().load();

然后你可以听取load事件,这样就可以获取所有数据,最后从那里选择所需的节点。

    treePanel.on("load", function( treeStore, records, successful, operation)){

    var id = 4; // This is the ID of the node that somehow you know in advance
    var node = treeStore.getNodeById(id);

    treePanel.expandPath(node.getPath());
});

HTH!