2013-10-16 35 views
0

我需要在ExtJS.I一些解決方案選擇有樹店:ExtJS的擴展,並且在啓動

Ext.onReady(function(){ 

    var storeTree = Ext.create('Ext.data.TreeStore', { 
    autoLoad:false, 
    expanded: false,  
    proxy: { 
     type: 'ajax', 
     url: 'getOneLevelChilds', 
    }, 

    root: { 
     text: 'Ext JS', 
     id: 'src', 
     expanded: true, 
     children:[] 
    }, 
    ... 
    ] 
}); 

,當我的樹負載在第一次我加載最後選擇子(例如昨天我打開樹並選擇之一。我保存它的JSON數據庫。所以現在我展開樹)

storeTree.load({ 
    url: 'getLastSelectedChild' 
}); 

OK,一切正常!但現在我需要一些解決方案。

當我在啓動時加載我的樹(它被加載時)我有JSON:

[ 
    {"id":3, "text":"first",}, 
    {"id":4, "text":"second",}, 
    { 
    id:"0", text: "third", expanded: true, children: 
       [ 
        { 
         id:"1", text: "child1", leaf: true 
        }, 
        { 
         id:"2", text: "child2", leaf: true 
        } 
       ] 

    }, 

] 

但是我也保存選定的節點ID在數據庫中。我知道id =「2」在yeasterday被選中。如何在啓動時自動選擇該節點? (只有在啓動時,只有當我的樹將被加載)。我怎樣才能做到這一點?

P.S當我使用代理樹商店,選擇不幹活這樣的:

var record = this.getStore().getNodeById('1'); 
this.getSelectionModel().select(record) 

工作當我不使用代理服務器。

而且,我需要選擇只在sturtup

回答

3

「只在啓動時」假設由你的意思商店的第一負載事件,你確實有一個樹面板(否則你不能選擇一個節點):

treeStore.on({ 
    'load': function(store) { 
     var node = store.getNodeById(2); // your id here 

     treePanel.getSelectionModel().select([node]); 

     // alternatively, if also want to expand the path to the node 
     treePanel.selectPath(node.getPath()); 
    }, 
    single: true 
});