- /*!
- * @author caizhiping
- * 下拉树
- */
- Ext.define('keel.TreeComboBox',{
- extend : 'Ext.form.field.ComboBox',
- alias: 'widget.keeltreecombo',
- store : new Ext.data.ArrayStore({fields:[],data:[[]]}),
- editable : false,
- allowBlank:false,
- listConfig : {resizable:true,minWidth:250,maxWidth:450},
- _idValue : null,
- _txtValue : null,
- callback : Ext.emptyFn,
- treeObj : new Ext.tree.Panel({
- border : false,
- height : 250,
- //width : 350,
- autoScroll : true,
- rootVisible: false,
- store: new Ext.data.TreeStore({
- nodeParam : 'bmjg.bmjgdm',
- proxy: {
- type: 'ajax',
- url: '/fs/actions/bmjgtree!ajaxTreeforCombobox',
- reader: 'json'
- },
- autoLoad : false,
- root: {
- name : 'GT',
- id: pbmjgdm,
- expanded: true
- }
- })
- }),
- initComponent : function(){
- this.treeRenderId = Ext.id();
- this.tpl = "<tpl><div id='"+this.treeRenderId+"'></div></tpl>";
- this.callParent(arguments);
- this.on({
- 'expand' : function(){
- if(!this.treeObj.rendered&&this.treeObj&&!this.readOnly){
- Ext.defer(function(){
- this.treeObj.render(this.treeRenderId);
- },300,this);
- }
- }
- });
- this.treeObj.on('itemclick',function(view,rec){
- if(rec){
- this.setValue(this._txtValue = rec.get('text'));
- this._idValue = rec.get('id');
- //设置回调
- this.callback.call(this,rec.get('id'), rec.get('text'));
- //关闭tree
- this.collapse();
- }
- },this);
- },
- getValue : function(){//获取id值
- return this._idValue;
- },
- getTextValue : function(){//获取text值
- return this._txtValue;
- },
- setLocalValue : function(txt,id){//设值
- this._idValue = id;
- this.setValue(this._txtValue = txt);
- }
- });
调用:
- /**下拉机构数*/
- var xltree=new keel.TreeComboBox({
- fieldLabel : '部门机构',
- name:'BMJGJC',
- anchor:'95%',
- //allowBlank:false,
- callback:function(id,text){
- //赋值给隐藏域
- T_RY_NEW_FORM.getForm().findField("BMJGDM").setValue(id);
- }
- });
效果图:
在ExtJS官方下载包中为我们提供了下拉树类库TreePicker.js,实现效果图:
代码:
xtype:
'treepicker'
,
fieldLabel:
'下拉树'
,
width: 400,
labelWidth: 60,
margin:
'100 0 0 150'
,
displayField:
'text'
,
rootVisible:
false
,
value:
''
,
minPickerHeight: 200,
store: Ext.create(
'Ext.data.TreeStore'
,{
fields: [
'id'
,
'text'
],
root: {
text:
'天朝部门'
,
expanded:
true
},
proxy: {
type:
'ajax'
,
url:
'app/data/tree.json'
,
reader: {
type:
'json'
}
}
})
|