Extjs 4 树面板重新加载和展开

发布于 2025-01-05 18:34:40 字数 965 浏览 4 评论 0原文

我正在使用带有 Json 数据的 Extjs4 树面板。我想重新加载树面板并需要将树菜单展开到指定节点。 我正在使用以下代码。请让我知道如何做到这一点。

//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 
   });
   } 

提前致谢

I'm using Extjs4 treepanel with Json data.I want reload the treepanel and need expand tree menu to specified node.
I'm using the following code. Please let me know how do this.

//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 
   });
   } 

Thanks in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

寄与心 2025-01-12 18:34:40

重新加载树,我认为调用它更简单

treePanel.getStore().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());
});

哈!

Reload the tree i think it's simpler to just call

treePanel.getStore().load();

then you can listen to the load event, so that the data is all fetched and finally from there select the desired node.

    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!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文