如何在extjs树中获取select节点的索引

How do we get index of select node in a extjs tree?

本文关键字:select 节点 索引 获取 extjs      更新时间:2023-09-26

在我的页面上有两棵树。页面上有表格。一棵树显示在页面上,另一棵树则显示在表单中。我创建了如下树:

var myTree1=外部创建('外部树面板'{store:store,//其中store是硬编码的json树数据。。。。});

类似地,myTree2是用不同的存储声明的。它显示在表格中。当我选择myTree2上的任何节点并单击创建按钮时,我必须能够在myTree1中的同一索引处添加一个新的叶节点。

我需要的帮助是:
1.如何获取所选节点的索引
2.如何转到myTree1中的索引,应该等于所选的索引myTree2。
3.如何在特定索引处添加叶节点

参考:
Ext JS 4 TreePanel文档
Ext JS 4 NodeInterface文档

  1. select事件同时提供索引和记录。如果您需要对其进行一般访问,myTree1.getSelectionModel().getSelection()将返回一个记录数组,然后您可以对照存储进行检查以获取索引。

  2. 我假设您要比较两个树上的选定记录。给定#1中的样本,请尝试以下操作:

    var tree1rec = myTree1.getSelectionModel().getSelection[0],
        tree2rec = myTree2.getSelectionModel().getSelection[0];
    // Perform comparison logic here
    // Note that if you're using two different stores, you can't
    // just do an equality test. You'll probably have to compare
    // individual store values.
    
  3. 节点是相对于树上的现有节点插入的。因此,如果你有一个按钮点击事件:

    function onButtonClick(button, eOpts) {
        var rec = myTree1.getSelectionModel().getSelection[0];
        if (rec) {
            var childNode = rec.createNode(/* some object here */);
            rec.appendChild(childNode);
        }
    }
    

细节会根据您的实际数据而有所不同,但这是一般模式。