2012-03-08 99 views
0

在我的页面上,我有2棵树。 页面上有表格。一页树显示在页面上,另一页显示在表单中。 我有如下创建树:我们如何获得extjs树中的select节点的索引?

 
var myTree1 = Ext.create('Ext.tree.Panel', { 
    store: store, //where store is hardcoded json tree data 
    .... 
}); 

同样myTree2声明了不同的商店。它显示在一个表单中。 当我在myTree2上的任意节点上选择并单击创建按钮时,我必须能够在同一个索引处的myTree1内添加一个新的叶节点。

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

回答

2

参考:
Ext JS 4 TreePanel documentation
Ext JS 4 NodeInterface documentation

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

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

相关问题