2013-10-16 23 views
-1

我有樹存儲。使用treeStore時選擇節點ExtJS(代理解決方案)

var store = Ext.create('Ext.data.TreeStore', { 
    root: { 
     autoLoad:false, 
     expanded: false, 
     children: [ 
      { 
       id:"0", text: "School Friends", expanded: true, children: 
       [ 
        { 
         id:"1", text: "Mike", leaf: true, name: "Mike", email: "[email protected]", phone: "345-2222" 
        }, 
        { 
         id:"select", text: "Laura", leaf: true, name: "Laura", email: "[email protected]", phone: "345-3333" 
        } 
       ] 
      } 

     ] 
    } 
}); 

和樹面板。

Ext.create('Ext.tree.Panel', { 
    title: 'Simple Tree', 
    width: 200, 
    height: 150, 
    store: store, 
    rootVisible: false, 
    renderTo: Ext.getBody(), 
    listeners:{ 
     afterrender:function(){ 
      var record = this.getStore().getNodeById('1'); 
      this.getSelectionModel().select(record) 
     } 
    } 
}); 

一切正常!但是當我改變商店,使用代理請求。選擇就是n * OT工作 *

var storeTree = Ext.create('Ext.data.TreeStore', { 
    autoLoad:true, 
    expanded: true, 

    proxy: { 
     type: 'ajax', 
     url: 'tree.json', 
    }, 

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

    folderSort: true, 
    sorters: [{ 
     property: 'text', 
     direction: 'ASC' 
    }] 
}); 

我用同樣的JSON

[ 

    {"id":4, "text":"second",}, 

    { 
    id:"0", text: "School Friends", expanded: true, children: 
       [ 
        { 
         id:"1", text: "Mike", leaf: true, name: "Mike", email: "[email protected]", phone: "345-2222" 
        }, 
        { 
         id:"select", text: "Laura", leaf: true, name: "Laura", email: "[email protected]", phone: "345-3333" 
        } 
       ] 

    }, 

] 

回答

0

例如一個解決辦法:

var storeTree = Ext.create('Ext.data.TreeStore', { 
    autoLoad:false, 
    expanded: false, 

    proxy: { 
     type: 'ajax', 
     url: 'tree2.json', 

     extraParams: {o: 'SELECTED'}, 
    }, 

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

    folderSort: true, 
    sorters: [{ 
     property: 'text', 
     direction: 'ASC' 
    }] 
}); 


storeTree.load({ 
    url: 'tree.json' 
}); 


storeTree.on({ 
    'load': function(store) { 
     var node = store.getNodeById("select"); // your id here 

     treePanel.getSelectionModel().select([node]); 
     treePanel.selectPath(node.getPath()); 
    }, 
    single: true 
});