Extjs4 实现下拉树
/*!
* @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);
}
});
效果图:

请问能不能发一下后台代码呢?
我在参考您的文章进行下拉树的异步刷新时,总是出现重复很多次的请求,而且对后端返回的JSON对象好像前端做了什么处理,总是看不到叶子节点
我在弹出窗口中添加此下拉树,第一次打开的时候正常,第二次打开弹出窗口时就下拉树被弹出窗口遮挡了,为什么?
//赋值给隐藏域
T_RY_NEW_FORM.getForm().findField("BMJGDM").setValue(id);
大哥能不能写完整点?上面的东东是从哪冒出来的
点击第一次正常,点击第二次就被遮挡了
贴上代码,帮忙看看,我在弹出窗口中添加此下拉树,第一次打开的时候正常,第二次打开弹出窗口时就下拉树被弹出窗口遮挡了,为什么?
Ext.require(); var micolor = 'color:blue;'; Ext.onReady(function() { Ext.QuickTips.init(); var tree = Ext.create('Ext.tree.Panel', { region : 'west', store : treeStore, viewConfig : { plugins : { ptype : 'treeviewdragdrop' } }, width : 150, title : '功能菜单', useArrows : false, listeners : { 'itemclick' : function(view, record, item, index, e) { var id = record.get('id'); var text = record.get('text'); var leaf = record.get('leaf'); // xltree.setLocalValue(text, id); }, scope : this } }); // tree.expandAll(); Ext.define('MyData', { extend : 'Ext.data.Model', fields : });
});
我在弹出窗口中添加此下拉树,第一次打开的时候正常,第二次打开弹出窗口时就下拉树被弹出窗口遮挡了,为什么?