一.首先引入对象ComboBoxTree
ComboBoxTree = Ext.extend(Ext.form.ComboBox, {
passName : 'id',
allowUnLeafClick : true,
// tpl: '<div id="treeTpl"></div>', //html代码
treeHeight : 180,
store : new Ext.data.SimpleStore({
fields : [],
data : [[]]
}),
//Default
editable : false, // 禁止手写及联想功能
mode : 'local',
triggerAction : 'all',
maxHeight : 500,
selectedClass : '',
onSelect : Ext.emptyFn,
emptyText : '请选择...',
clearValue : function() {
if (this.passField) {
this.passField.value = '';
}
this.setRawValue('');
},
setPassValue: function(passvalue){
if (this.passField)
this.passField.value = passvalue;
},
onTreeSelected : function(node) {
},
treeClk : function(node, e) {
if (!node.isLeaf() && !this.allowUnLeafClick) {
e.stopEvent();// 非叶子节点则不触发
return;
}
this.setValue(node.text);// 设置option值
this.collapse();// 隐藏option列表
if (this.passField)
this.passField.value = node.id;// 以树的节点ID传递
// 选中树节点后的触发事件
this.fireEvent('treeselected', node);
},
initComponent : function() {
ComboBoxTree.superclass.initComponent.call(this);
this.tree.autoScroll = true;
this.tree.height = this.treeHeight;
this.tree.containerScroll = false;
this.tplId = Ext.id();
// overflow:auto"
this.tpl = '<div id="' + this.tplId + '" style="' + this.treeHeight
+ '";overflow:hidden;"></div>';
this.addEvents('treeselected');
// this.on('treeselected',this.onTreeSelected,this);
},
listeners : {
'expand' : {
fn : function() {
if (!this.tree.rendered && this.tplId) {
this.tree.render(this.tplId);
}
this.tree.show();
},
single : true
},
'render' : {
fn : function() {
this.tree.on('click', this.treeClk, this);
if (this.passName) {
this.passField = this.getEl().insertSibling({
tag : 'input',
type : 'hidden',
name : this.passName,
id : this.passId || Ext.id()
}, 'before', true)
}
this.passField.value = this.passValue !== undefined
? this.passValue
: (this.value !== undefined ? this.value : '');
this.el.dom.removeAttribute('name');
}
},
'beforedestroy' : {
fn : function(cmp) {
this.purgeListeners();
this.tree.purgeListeners();
}
}
}
});
Ext.reg('combotree', ComboBoxTree);
二.生成含有树的下拉框
//定义一个树形
var contenttree = new Ext.tree.TreePanel({
rootVisible:false,
root:new Ext.tree.AsyncTreeNode({
id:'0',
text:'',
expanded:true,
loader:new Ext.tree.TreeLoader({
dataUrl:'operation/base/querycontenttree.jsp'
})
})
});
//树在Load时自动展开
contenttree.on('load', function(node, checked) {
node.expand();
node.eachChild(function(child) {
child.expand();
});
});
//定义下拉树对象
var contenttreecombo = new ComboBoxTree({
width:130,
allowBlank : false,
//allowUnLeafClick:false,//只允许选择叶子
treeHeight:200,
emptyText:'请选择...',
tree:contenttree
});
分享到:
相关推荐
支持ext3.0以上版本,希望大家能用到-----------------------------------
选择所在大区&&大区中选择一个社区-->选取-->下拉框; 选择所在大区接种点(自由选择) 选择所选日期内是否可以预约(后台数据库); 预约提醒-->短信or邮件 预约成功与约定时间前一天; 疫苗(大区显示全部疫苗, 分区...
jQuery插件---mcdropdow.(仿下拉框多层次)jQuery插件---mcdropdow.(仿下拉框多层次)jQuery插件---mcdropdow.(仿下拉框多层次)jQuery插件---mcdropdow.(仿下拉框多层次)jQuery插件---mcdropdow.(仿下拉框多层次)
EXT下拉框显示树形结构源代码EXT下拉框显示树形结构源代码
bootstrap-select 下拉框demobootstrap-select 下拉框demobootstrap-select 下拉框demobootstrap-select 下拉框demobootstrap-select 下拉框demobootstrap-select 下拉框demobootstrap-select 下拉框demobootstrap-...
select2-4.0.12.zip(下拉框带搜索css和js)
三级联动下拉框, 也可以扩展为N级联动, 自动判别 label, value, 速度快,项目中肯定用得到
关于解决ElementUi中select框在页面滚动时el-option超出元素区域的问题+ cascader滚动超出问题
TreeCombo,Ext TreeCombo 树形 下拉框,树形下拉框
bootstrap树控件使用bootstrap-treeview.js树形控件在下拉框select中显示,带树形的下拉框
bootstrap树控件使用树形控件在下拉框select中显示,实现树形下拉框
计算机软件-商业源码-磁盘下拉框光驱等出错问题.zip
批量添加数据的表单界面(表单含树形下拉框)vue + element 通过【npm install】自行下载资源,生成node_modules文件夹
layui组件之树形下拉框例子,看完你就会写下拉树了。不过同时还需要下载ztree的相关js和style 不过压缩包里都有呢!希望对大家有所帮助
bootstrap-table插件:bootstrap-editable,可编辑下拉框,以及代码实例,
extjs多选下拉框,Ext.ux.form.LovCombo,extjs 以修复多选下拉框火狐下取不到值的问题,火狐下div不显示背景色的问题
<script type="text/javascript" src="jquery-...<option value="2">Option 2</option> <option value="3">Option 3</option> <option value="4">Option 4</option> <option value="5">Option 5</option> </select>
使用js判断用户流览器语言,然后导入相关的css进行显示。只需要简单修改就可以用于自己的项目。可用于pc端和移动端 web前端开发(深圳)群: 73269871