Ext Combobox 动态下拉树实现
来源:互联网 发布:windows错误恢复 编辑:程序博客网 时间:2024/06/01 09:57
在最近的一个项目中,想利用Ext combobox实现一个动态的下拉树,无奈官方中也没有例子,网上很多例子也是坑爹的,, 决定自已修改 然后实现一个动态的下拉树,废话少说 ,看代码:
下面是应用
树的加载 ,采用动态加载 需要的才加载上来,
Ext.ns('Boat.UI');
// 树形下拉框
Boat.UI.TreeCombox = Ext.extend(Ext.form.ComboBox, {
store : new Ext.data.SimpleStore({
fields : [],
data : [[]]
}),
editable : false,
mode : 'local',
triggerAction : 'all',
emptyText : '请选择...',
treeConfig : {
border : false,
autoScroll : true,
height : 200
},
initComponent : function() {
this.hiddenName = this.name;
Ext.apply(this.tree, this.treeConfig);
this.tpl = '<div id="tree-' + this.id + '"></div>';
Boat.UI.TreeCombox.superclass.initComponent.call(this);
this.on('expand', this.expandtree, this);
this.tree.on('click', this.clicktree, this);
},
onViewClick : Ext.emptyFn,
assertValue : Ext.emptyFn,
expandtree : function() {
this.tree.render('tree-' + this.id);
this.tree.expand();
},
clicktree : function(node) {
this.setValue(node);
this.collapse();
//如果要需求是单独叶节点可选时 可这样做
/*if (node.isLeaf()) {
this.setValue(node);
this.collapse();
}*/
},
setValue : function(v) {
this.hiddenField.value = v.id;
Ext.form.ComboBox.superclass.setValue.call(this, v.text);
this.value = v.id;
},
onDestroy : function() {
this.un('expand', this.expandtree, this);
Ext.destroy(this.tree);
Boat.UI.TreeCombox.superclass.onDestroy.call(this);
}
});
Ext.reg('treecombobox', Boat.UI.TreeCombox);
// 树形下拉框
Boat.UI.TreeCombox = Ext.extend(Ext.form.ComboBox, {
store : new Ext.data.SimpleStore({
fields : [],
data : [[]]
}),
editable : false,
mode : 'local',
triggerAction : 'all',
emptyText : '请选择...',
treeConfig : {
border : false,
autoScroll : true,
height : 200
},
initComponent : function() {
this.hiddenName = this.name;
Ext.apply(this.tree, this.treeConfig);
this.tpl = '<div id="tree-' + this.id + '"></div>';
Boat.UI.TreeCombox.superclass.initComponent.call(this);
this.on('expand', this.expandtree, this);
this.tree.on('click', this.clicktree, this);
},
onViewClick : Ext.emptyFn,
assertValue : Ext.emptyFn,
expandtree : function() {
this.tree.render('tree-' + this.id);
this.tree.expand();
},
clicktree : function(node) {
this.setValue(node);
this.collapse();
//如果要需求是单独叶节点可选时 可这样做
/*if (node.isLeaf()) {
this.setValue(node);
this.collapse();
}*/
},
setValue : function(v) {
this.hiddenField.value = v.id;
Ext.form.ComboBox.superclass.setValue.call(this, v.text);
this.value = v.id;
},
onDestroy : function() {
this.un('expand', this.expandtree, this);
Ext.destroy(this.tree);
Boat.UI.TreeCombox.superclass.onDestroy.call(this);
}
});
Ext.reg('treecombobox', Boat.UI.TreeCombox);
下面是应用
{ x : 30,
y : 35,
xtype : 'treecombobox', //上面注册的 treecombobox
name:'parentId', //提交到后台得数据
tree : categorytree //指定要加载的树
}
y : 35,
xtype : 'treecombobox', //上面注册的 treecombobox
name:'parentId', //提交到后台得数据
tree : categorytree //指定要加载的树
}
树的加载 ,采用动态加载 需要的才加载上来,
var treeLoader = new Ext.tree.TreeLoader({
dataUrl : './Category/getTreeCategory.action',
baseParams : {}
});
var treenode = new Ext.tree.AsyncTreeNode({
id : 'root',
text : '类别',
leaf : false
});
/**
* treeloader 加载之前根据参数 parendId动态加载树节点
*/
treeLoader.on('beforeload', function(loader, node) {
loader.baseParams.parentId = (node.attributes.id == 'root'
? 0
: node.attributes.id);
})
var categorytree = new Ext.tree.TreePanel({
animate : true,
border : false,
loader : treeLoader,
root : treenode
});
dataUrl : './Category/getTreeCategory.action',
baseParams : {}
});
var treenode = new Ext.tree.AsyncTreeNode({
id : 'root',
text : '类别',
leaf : false
});
/**
* treeloader 加载之前根据参数 parendId动态加载树节点
*/
treeLoader.on('beforeload', function(loader, node) {
loader.baseParams.parentId = (node.attributes.id == 'root'
? 0
: node.attributes.id);
})
var categorytree = new Ext.tree.TreePanel({
animate : true,
border : false,
loader : treeLoader,
root : treenode
});
- Ext Combobox 动态下拉树实现
- Ext.form.ComboBox 动态加载数据后设置下拉选项
- Ext.form.field.ComboBox下拉项动态改变
- 使用EXT实现ComboBox多列下拉列表
- 扩展Ext的Combobox实现多选下拉列表
- 扩展Ext的Combobox实现多选下拉列表
- Ext ComboBox 动态查询
- ext下拉列表(ComboBox篇)
- Ext combobox 的动态改变
- Ext combobox 动态模糊匹配
- Ext combobox 动态模糊匹配
- EXT Ext combobox 动态模糊匹配
- Ext.form.ComboBox 表格下拉最终版本
- ext combobox 下拉框显示位置问题
- TOPGP5.3:combobox动态下拉
- combobox 动态绑定数据源,利用EasyUI的 combobox插件实现类似百度下拉提示信息
- 可输入可联想的下拉列表的实现——Ext ComboBox
- 可输入可联想的下拉列表的实现——Ext ComboBox
- Excel 绘制表格 详解!
- 安装 SQL Server 2008 需要 Windows PowerShell
- java 中 springmvc + openjpa 配置 注解
- IOS人机界面指南-数据摘要
- Web应用界面设计规范
- Ext Combobox 动态下拉树实现
- 黑马程序员日记12-----泛型
- A simple poem
- android解析XML总结(SAX、Pull、Dom三种方式)附带DOM4J、JDOM
- Vim快速选中、删除、复制引号或括号中的内容
- 关于List<object>中按对象的某个属性值排序的方法
- 黑马程序员日记13----多线程
- shell编程基础
- 非负矩阵分解:数学的奇妙力量