使用treeStore ExtJS时选择节点(代理解决方案)

Posted

技术标签:

【中文标题】使用treeStore ExtJS时选择节点(代理解决方案)【英文标题】:selecting node when using treeStore ExtJS (proxy solution) 【发布时间】:2013-10-16 09:13:17 【问题描述】:

我有树店。

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: "mike@***.com", phone: "345-2222"
                    ,
                    
                        id:"select", text: "Laura", leaf: true, name: "Laura", email: "laura@***.com", 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)
        
    
);

一切正常!但是当我更改商店时,使用代理请求。选择没有*不起作用*

    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: "mike@***.com", phone: "345-2222"
                    ,
                    
                        id:"select", text: "Laura", leaf: true, name: "Laura", email: "laura@***.com", phone: "345-3333"
                    
                ] 

    ,

]

【问题讨论】:

【参考方案1】:

例如一种解决方案:

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

【讨论】:

以上是关于使用treeStore ExtJS时选择节点(代理解决方案)的主要内容,如果未能解决你的问题,请参考以下文章

ExtJS4 树形面板问题

Extjs TreeStore,多个异步请求,treepanel渲染错位

为啥 Extjs 4.0.7 TreeStore 会自动调用 http delete 方法?

如何从 TreeStore Extjs4.1 获取数据

extjs 4.1 treestore 延迟加载:q 是,它分支吗?

EXTJS 4.1 如何在不重新加载 TreeStore 的情况下删除过滤器