当前位置: 代码迷 >> Web前端 >> Ext treepanel 加载时 默许选中第一条叶子节点
  详细解决方案

Ext treepanel 加载时 默许选中第一条叶子节点

热度:702   发布时间:2013-03-01 18:33:02.0
Ext treepanel 加载时 默认选中第一条叶子节点
这篇文章的标题已经很清楚的表明这篇文章是要干嘛了,工作中遇到的问题,解决之后做个笔记,给其他的朋友一个思路的建议也不错,废话不多说,请看代码
     	//默认选中第一条叶子节点并展开
     	var panelStore = this.store;
     	panelStore.on('load',function(store,node,records,successful,eOpts){
			if(successful && records.length>0 && node){
				for(var i = 0; i<records.length;i++){
					var leafNode = getLeafNode(node);
					if(leafNode!=''){
						Ext.getCmp('queryList').getSelectionModel().select(leafNode);
						if(!leafNode.get('expanded')){
		    				leafNode.expand();
		    			}
						break;
					}
				}
			}
    	});
		getLeafNode = function(node){
			var leafNode='';
			if(node){
				if(!node.isLeaf()&&node.hasChildNodes()){
					var childrenNodes = node.childNodes;
					for(var i = 0;i<childrenNodes.length;i++){
						var childrenNode = childrenNodes[i];
						leafNode = getLeafNode(childrenNode);
						if(leafNode==''||leafNode==null){
							continue;
						}
						return leafNode;
					}
				}else if(node.isLeaf()){
					return node;
				}
			}
//			console.log('end:'+leafNode);
			return leafNode;
		}