在做OECP平台的登陆页面时,需要选择相应的公司进行登陆,公司的选择是树形结构的,而extjs的下拉combobox为列表结构,为了让页面操作更加简单,决定将下拉列表改造成下拉树。
在这里主要用到了Extjs的extend的语法,扩展比较简单,直接上代码吧。
js 代码
- Ext.ns("OECP.ui");
-
-
-
-
-
-
-
-
- OECP.ui.ComboBoxTree = Ext.extend(Ext.form.ComboBox, {
-
-
-
-
-
- callback : Ext.emptyFn,
- store : new Ext.data.SimpleStore({
- fields : [],
- data : [[]]
- }),
- editable : this.editable||false,
- mode : 'local',
- emptyText : this.emptyText||"请选择",
- allowBlank : this.allowBlank||true,
- blankText : this.blankText||"必须输入!",
- triggerAction : 'all',
- maxHeight : 200,
- anchor : '95%',
- displayField : 'text',
- valueField : 'id',
- tpl : "<tpl for='.'><div style='height:200px'><div id='tree'></div></div></tpl>",
- selectedClass : '',
- onSelect : Ext.emptyFn,
-
-
-
-
-
- rootText : this.rootText||'root',
-
-
-
-
-
- treeUrl : this.treeUrl,
- tree : null,
- initComponent : function() {
-
- this.tree = new Ext.tree.TreePanel({
- height : 200,
- scope : this,
- autoScroll : true,
- split : true,
- root : new Ext.tree.AsyncTreeNode({
- expanded : true,
- id : '_oecp',
- text : this.rootText
- }),
-
- loader : new Ext.tree.TreeLoader({
- url : this.treeUrl
-
- }),
- rootVisible : true
- });
- var c = this;
-
-
-
- this.tree.on('click', function(node) {
- if (node.id != null && node.id != '') {
- if (node.id != '_oecp') {
- c.setValue(node.text);
- c.callback.call(this, node.id, node.text);
- c.collapse();
- } else {
- Ext.Msg.alert("提示", "此节点无效,请重新选择!")
- }
-
- }
- })
-
- this.on('expand', function() {
- this.tree.render('tree');
- this.tree.expandAll();
- });
-
- OECP.ui.ComboBoxTree.superclass.initComponent.call(this);
- }
-
- })
在页面上如下使用:xhtml 代码
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
- <html>
- <head>
- <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
- <title>ComboBoxTree.html</title>
- <link rel="stylesheet" type="text/css"
- href="../../extjs/resources/css/ext-all.css" />
- <script type="text/javascript"
- src="../../extjs/adapter/ext/ext-base.js"></script>
- <script type="text/javascript" src="../../extjs/ext-all.js"></script>
- <script type="text/javascript" src="../core/ComboBoxTree.js"></script>
- </head>
-
- <body>
- <div id="cbt"></div>
- </body>
- </html>
- <script type="text/javascript">
- Ext.onReady(function() {
- new OECP.ui.ComboBoxTree({
- renderTo:"cbt",
- treeUrl:"ComboBoxTree.json",
- editable:false,
- rootText:"选择公司",
- valueField:"com",
- displayField:"_com",
- callback:function(id,text){
- alert(id);
- alert(text);
- //可以做更多的处理。
- }
- });
- })
- </script>
附件中包含了该组件源代码和一个demo。
OECP平台正在研发之中,在第一个稳定版本发布的时候,将开放相关的API。
相关的API,可参见:http://prj.oecp.cn/projects/oecp-platform/wiki/OECPuiComboBoxTree
分享到:
相关推荐
Extjs 下拉树 下拉多选树 支持多选 全选/全不选 下拉多选框
NULL 博文链接:https://dengli19881102.iteye.com/blog/1046190
Extjs4下拉树菜单 ComboBoxTree 支持单选和多选并且支持展开选中指定节点的通用控件 在项目中已经成熟运用 值得收藏和运用
该资源主要展示了在Extjs6中Combobox控件实现下拉选择多个数据的功能
ExtJs4.2没有直接提供下拉树这个组件,但是有例子可以用,文件位置:ext-4.2.1.883\examples\ux\TreePicker.js 但是它有点小毛病吧:默认显示了根节点;达到最小高度时再展开节点,高度不能自动调整。 所以我做了一...
extjs实现的下拉树的核心代码,包括js,jsp,对有需要的同仁提供参考与学习之用
ExtJs4实现下拉树选择框ComboTree, 文档中包含代码。
extjs下拉树
功能:extjs4 下拉菜单树 combobox+tree 支持单选多选等 收集两款,仅需要1分。
ExtJs3下拉树 分两种方式调用:第一种: xtype : 'combotree', name : 'dm', fieldLabel : 'dm', tree : this.ct this.ct = new Ext.tree.TreePanel({ autoScroll : true, height : 250, border : false, ...
ExtJS4下拉树组件 ExtJS4下拉树组件
extjs 自动补全,模拟下拉列表combobox
Extjs4多选树,支持多选和单选,能够实现默认值选中,数据存放在json,里面有明确的提示信息。很适合初学者借鉴学习
自定义下拉树,你懂的,内附图和前后台源代码
Extjs4下拉菜单中用Grid显示,有单选,和多选两个控件,完美通用代码控件,绝对让你好用,值得收藏^-^
extjs 树形下拉列表框,可以进行数据选择,数据回显。
extjs editgrid combobox 回显extjs editgrid combobox 回显extjs editgrid combobox 回显extjs editgrid combobox 回显
extjs4 框架实现树形结构的下拉框,并支持多选、复选,项目中开发实际用到的,这里提供了前段的js代码,大家有用到的,可以进行参考。
Extjs-多功能下拉树列表.docExtjs-多功能下拉树列表.docExtjs-多功能下拉树列表.docExtjs-多功能下拉树列表.docExtjs-多功能下拉树列表.docExtjs-多功能下拉树列表.docExtjs-多功能下拉树列表.doc
Extjs 下拉列表