ExtJS Tree刷新后自动展开并选择节点

来源:互联网 发布:安卓应用商店推荐 知乎 编辑:程序博客网 时间:2024/04/27 16:58
 
Ext.onReady(function(){     Ext.BLANK_IMAGE_URL = '../js/extjs/3.2.0/resources/images/default/s.gif';     Ext.chart.Chart.CHART_URL = '../js/extjs/3.2.0/resources/charts.swf';     Ext.QuickTips.init();     testTreeGrid();   });     function testTreeGrid(){     var tree = new Ext.ux.tree.TreeGrid({       title: '地市',       width: 550,       height: 300,       dataUrl: 'treegrid-data.json',       renderTo: Ext.getBody(),       enableDD: true,       columns:[{         header: 'ID',         dataIndex: 'id',         width: 200       },{         header: '名称',         dataIndex: 'fdcName',         width: 180       },{         header: '描述',         dataIndex: 'fdcDesp',         width: 100,         align: 'center',         sortType: 'string',         tpl: new Ext.XTemplate('{fdcDesp:this.formatDesp}', {           formatDesp: function(v) {             return v||'-'          }         })       }],       tbar:[{         text:'当前路径',         tooltip:'保存当前选择节点的路径',         scope:this,         handler:function(b,e){           //获取当前选择节点的路径           var node = tree.getSelectionModel().getSelectedNode();           var path = node.getPath('id');           Ext.getCmp('tf').setValue(path);         }       },{         xtype:'textfield',         id:'tf',         width:300,         value:''      },{         text:'选择路径',         scope:this,         handler:function(b,e){           var path = Ext.getCmp('tf').getValue();           //展开路径,并在回调函数里面选择该节点           tree.expandPath(path,'id',function(bSucess,oLastNode){             tree.getSelectionModel().select(oLastNode);           });         }       },{         text:'选择江门',         scope:this,         handler:function(b,e){           var path = '/xnode-11/cn86/gd020/gd020areas/jm0750';           //展开路径,并在回调函数里面选择该节点           tree.expandPath(path,'id',function(bSucess,oLastNode){             tree.getSelectionModel().select(oLastNode);           });         }       },{         text:'重载',         tooltip:'重载数据并选择上一次的节点',         scope:this,         handler:function(b,e){           var path = tree.getSelectionModel().getSelectedNode().getPath('id');           //重载数据,并在回调函数里面选择上一次的节点           tree.getLoader().load(tree.getRootNode(),function(treeNode){             //展开路径,并在回调函数里面选择该节点             tree.expandPath(path,'id',function(bSucess,oLastNode){               tree.getSelectionModel().select(oLastNode);             });           },this);         }       }]     });   }  

原创粉丝点击