2012-03-08 102 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); 
        } 
    } 
    

細節將根據您的實際數據有所不同,但這是一般模式。

相關問題