`
牧羊人
  • 浏览: 211132 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

ComboBoxTree

EXT 
阅读更多
参考别人的改的

Ext.namespace("Ext.ux.form");
/**
 * create by wjc
 */
Ext.ux.form.ComboBoxTree = Ext.extend(Ext.form.ComboBox, {
	treeId : Ext.id()+'-tree',
	maxHeight :300,
	selectedClass : '',
	mode : 'local',
	triggerAction: 'all',
	onSelect : Ext.emptyFn,
	editable : false,
	
	//all:所有结点都可选中
	//exceptRoot:除根结点,其它结点都可选
	//folder:只有目录(非叶子和非根结点)可选
	//leaf:只有叶子结点可选
    selectNodeModel : 'exceptRoot',
	//private   
    initComponent: function(){
       this.initComboBoxTree();
       Ext.ux.form.ComboBoxTree.superclass.initComponent.call(this);
    }, 
    initComboBoxTree:function(){
    	this.tpl = new Ext.Template('<tpl for="."><div style="height:'+this.maxHeight+'px"><div id="'+this.treeId+'"></div></div></tpl>');
	    this.store = new Ext.data.SimpleStore({fields:[],data:[[]]});
	    if(!this.tree){
	    	var initComboBoxTree_Page =this;
		    this.tree = new Ext.tree.TreePanel({
				loader: new Ext.tree.DWRTreeLoader({    
						dataUrl:this.DWRfunc,
						isteners : {   
							'beforeload' : function(node) {  
						          initComboBoxTree_Page.getLoader().args[0]=(node.id!='0'?node.id:"1");   
							 }   
					    } 
					}),
				root : new Ext.tree.AsyncTreeNode({   
						  text: this.rootlable,  
						  draggable:false,   
						  id:'1' 
					 })
		    });	
	    }
    },
	expand : function(){
		Ext.ux.form.ComboBoxTree.superclass.expand.call(this);
		if(!this.tree.rendered){
			this.tree.height = this.maxHeight;
			this.tree.border=false;
			this.tree.autoScroll=true;
	        if(this.tree.xtype){
				this.tree = Ext.ComponentMgr.create(this.tree, this.tree.xtype);
			}
			this.tree.render(this.treeId);
	        var combox = this;
	        this.tree.on('click',function(node){
	        	var isRoot = (node == combox.tree.getRootNode());
	        	var selModel = combox.selectNodeModel;
	        	var isLeaf = node.isLeaf();
	        	if(isRoot && selModel != 'all'){
	        		return;
	        	}else if(selModel=='folder' && isLeaf){
	        		return;
	        	}else if(selModel=='leaf' && !isLeaf){
	        		return;
	        	}
	        	combox.setValue(node);
	        	combox.collapse();
	        });
			var root = this.tree.getRootNode();
			if(!root.isLoaded())
				root.reload();
		}
    },
    
	setValue : function(node){
        var text = node; 
        if(node.text)
          text = node.text;
        if(this.valueField){
            var r = this.findRecord(this.valueField, node.text);
            if(r){
                text = r.data[this.displayField];
            }else if(Ext.isDefined(this.valueNotFoundText)){
                text = this.valueNotFoundText;
            }
        }
        this.lastSelectionText = text;
        if(this.hiddenField){
            this.hiddenField.value = node.text; 
        }
        Ext.ux.form.ComboBoxTree.superclass.setValue.call(this, text);
        this.value = node.text; 
        return this;
    },
    
    getValue : function(){
    	return typeof this.value != 'undefined' ? this.value : Ext.ux.form.ComboBoxTree.superclass.getValue.call(this);
    }
});

Ext.reg('combotree', Ext.ux.form.ComboBoxTree);
  • 大小: 24.3 KB
分享到:
评论
1 楼 被剥削的程序员 2013-12-20  
你好我在引用你的comboxtree解决问题的时候,发现点击父节点时候没法把子节点全部选中。想改你的源码发现无从下手,能否提供个思路给我。急等着改
本人菜鸟求学习

相关推荐

Global site tag (gtag.js) - Google Analytics