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

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

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值