EXTJS4下拉树写法

/**
    * 创建下拉树
    * @param fieldLabel 标签
    * @param name 
    * @param url 请求URL
    * @param anchor 
    * @returns
    */
   createTreeCombo: function(fieldLabel, name, url, anchor, allowBlank) {
	   	var df = Ext.create('Ext.form.field.Picker', {
			fieldLabel:fieldLabel,
			hiddenValue:'',
			labelAlign:'right',
			anchor:anchor,
			allowBlank:allowBlank,
			beforeLabelTextTpl: allowBlank ? '':required,
		    createPicker: function() {
		        return Ext.create('Ext.tree.Panel', {
		        	pickerField: this,
		            hidden: true,
		            height : self.treeHeight||300,  
		            rootVisible : false,//是否显示根节点
					autoScroll :true,
		            floating: true,
		            minHeight: 300,
				    store : Ext.create('Ext.data.TreeStore', {  
				        root : {  
				            id:'0',
				            expanded : true,
				            hidden:true
				        },
			        	proxy: {
			       	         type: 'ajax',
			    	         actionMethods:'post',
			    	         url: url,
			    	         reader: {
			    	             type: 'json'
			    	         }
			            },
			            fields:['id', 'text']
				    }),
				    listeners:{
		                select: function(thisTree, record, index, obj ){
		                	this.pickerField.setHiddenValue(record.data.id);
		                    this.pickerField.setValue(record.data.text);
		                    this.pickerField.collapse();
		                }
		            }
		        });
		    },
		    setHiddenValue: function(value) {
		    	this.hiddenValue = value;
		    },
		    getHiddenValue: function() {
		    	return this.hiddenValue;
		    }
		});
		return df;
   }

取得下拉框中VALUE值用getHiddenValue()方法,取得显示的TEXT值用getValue();

你可能感兴趣的:(JavaScript)