• 设为首页
  • 收藏本站
  • 积分充值
  • VIP赞助
  • 手机版
  • 微博
  • 微信
    微信公众号 添加方式:
    1:搜索微信号(888888
    2:扫描左侧二维码
  • 快捷导航
    福建二哥 门户 查看主题

    Extjs实现下拉菜单效果

    发布者: 琛瑞6678 | 发布时间: 2025-8-13 21:46| 查看数: 39| 评论数: 0|帖子模式

    本文实例为大家分享了Extjs实现下拉树效果,供大家参考,具体内容如下
    1. <!DOCTYPE html>
    2. <html>
    3. <head>
    4. <meta charset="UTF-8">
    5. <title>text8</title>

    6.   <link rel="stylesheet" type="text/css" href="../../../ext-4.2.1/resources/css/ext-all.css" >
    7.   <script type="text/javascript" src="../../../ext-4.2.1/bootstrap.js"></script>

    8. </head>
    9. <body>
    10.   <script>
    11.        Ext.define('TreeComboBox',{
    12.           extend : 'Ext.form.field.ComboBox',
    13.           store : {
    14.             fields:[],
    15.             data:[[]]
    16.           },
    17.           width:300,
    18.           editable : false,
    19.           allowBlank:false,
    20.           multiSelect : true,
    21.           listConfig : {
    22.             resizable:false,
    23.             minWidth:150,
    24.             maxWidth:250,
    25.           },
    26.           _idValue : null,
    27.           _txtValue : null,
    28.           callback : Ext.emptyFn,
    29.           treeObj : null,
    30.           initComponent : function(){
    31.               this.treeObj=new Ext.tree.Panel({
    32.                 border : false,
    33.                 autoScroll : true,
    34.                 rootVisible: false,
    35.                 renderTo:this.treeRenderId,
    36.                 root: {
    37.                   text: 'root',draggable: false,expanded: true,
    38.                     children:[
    39.                       {
    40.                       text:'一级节点',expanded: true, checked:false ,
    41.                         children:[
    42.                           { text:'二级节点1',leaf:true,checked:false},
    43.                           { text:'二级节点2',leaf:true,checked:false}
    44.                           ]
    45.                         } ,
    46.                         {
    47.                       text:'一级节点',expanded: true, checked:false ,
    48.                         children:[
    49.                           { text:'二级节点1',leaf:true,checked:false},
    50.                           { text:'二级节点2',leaf:true,checked:false}
    51.                           ]
    52.                         }
    53.                    ]
    54.                  } ,
    55.                listeners:{
    56.                  checkchange:function(node,state){
    57.                    if(node.hasChildNodes()){
    58.                      for(var i=0;i<node.childNodes.length;i++){
    59.                        node.childNodes[i].set('checked',state);
    60.                        }
    61.                      }
    62.                    }
    63.                  }
    64.               });   
    65.             
    66.               this.treeRenderId = Ext.id();
    67.               this.tpl = "<tpl><div id='"+this.treeRenderId+"'></div></tpl>";   
    68.               this.callParent(arguments);
    69.               this.on({
    70.                   'expand' : function(){
    71.                     if(!this.treeObj.rendered&&this.treeObj&&!this.readOnly){
    72.                         Ext.defer(function(){
    73.                             this.treeObj.render(this.treeRenderId);
    74.                         },100,this);
    75.                     }
    76.                 }
    77.             });
    78.                
    79.               this.treeObj.on('itemclick',function(view,rec){
    80.                 /* var roonodes = this.treeObj.getRootNode().childNodes;  //获取主节点
    81.                  var childnodes = node.childNodes; //获取zi节点
    82.                  if (roonodes.getView().getSelectionCount()==1) {
    83.                   for(var i=0;i<childnodes.length;i++){
    84.                     this.setValue(this._txtValue = rec.get('text'));  
    85.                   }
    86.                  }*/
    87.                   if(rec){
    88.                     //node.getUI().checkbox.indeterminate = true; //半选中状态
    89.                     this.setValue(this._txtValue = rec.get('text'));         
    90.                     //this.collapse();//关闭tree
    91.                   }
    92.               },this);
    93.           },
    94.       });
    95.         
    96.     //实例化下拉树
    97.     var xltree1=new TreeComboBox({
    98.       fieldLabel : '下拉树1',
    99.       name:'xltree1111',
    100.       allowBlank:true
    101.     });  
    102.     var xltree2=new TreeComboBox({
    103.       fieldLabel : '下拉树2',
    104.       name:'xltree2222',
    105.       allowBlank:true
    106.     });
    107.         
    108.         
    109.     Ext.create('Ext.form.Panel', {
    110.       renderTo: Ext.getBody(),
    111.       width: 500,
    112.       bodyPadding: 10,
    113.       title: 'TreeComboBox',
    114.       items: [xltree1, xltree2]
    115.     });
    116.   </script>
    117. </body>
    118. </html>
    复制代码
    问题:当选中复选框时候,如何使全部选中的条目添加显示到combobox中?
    效果:

    下面是另一个:
    1. <!DOCTYPE html>
    2. <html>
    3. <head>
    4. <meta charset="UTF-8">
    5. <title>tabpanel</title>

    6.   <link rel="stylesheet" type="text/css" href="../../../ext-4.2.1/resources/css/ext-all.css" >
    7.   <script type="text/javascript" src="../../../ext-4.2.1/bootstrap.js"></script>


    8. </head>
    9. <body>
    10.   <script>
    11.         Ext.onReady(function(){
    12.             Ext.create('Ext.window.Window',{
    13.                 id: 'docaddId',
    14.                 title: 'Preferences',
    15.                 buttonAlign: 'center',
    16.                 width:500,
    17.                 layout:'fit',
    18.                 //height:400,
    19.                 resizable:false,

    20.                  
    21.                 items:
    22.                     Ext.create('Ext.tab.Panel', {
    23.                       //renderTo: Ext.getBody(),
    24.                         
    25.                       items: [{
    26.                         title: 'A',
    27.                         
    28.                         items:[
    29.                         
    30.                         //Process and associated workstation下拉选框
    31.                         {

    32.                   xtype:'container',
    33.                   fieldLabel:'Workstation',

    34.                   items:[{
    35.                       xtype:"combobox",
    36.                       name : 'Process and associated workstation',  
    37.                   fieldLabel : 'Workstation',  
    38.                   id:'aaa',
    39.                   layout:'fit',
    40.                   width:480,
    41.                   editable : false,  
    42.                   allowBlank : false,  
    43.                   multiSelect : true,  
    44.                   store : {  
    45.                   fields : ['workstationId', 'workstationName'],  
    46.                   data : [  
    47.                     {'workstationId':'0',workstationName:'workstation01'},  
    48.                     {'workstationId':'1',workstationName:'workstation02'},  
    49.                     {'workstationId':'2',workstationName:'workstation03'},  
    50.                     {'workstationId':'3',workstationName:'workstation04'}  
    51.                   ]  
    52.                   },  
    53.                   listConfig : {  
    54.                   itemTpl : Ext.create('Ext.XTemplate','<input type=checkbox>{[values.workstationName]}'),  
    55.                   onItemSelect : function(record) {  
    56.                     var node = this.getNode(record);  
    57.                     if (node) {  
    58.                     Ext.fly(node).addCls(this.selectedItemCls);  
    59.                     var checkboxs = node.getElementsByTagName("input");  
    60.                     if (checkboxs != null)  
    61.                       var checkbox = checkboxs[0];  
    62.                     checkbox.checked = true;  
    63.                     }  
    64.                   },  
    65.                   listeners : {  
    66.                     itemclick : function(view, record, item, index, e, eOpts) {  
    67.                     var isSelected = view.isSelected(item);  
    68.                     var checkboxs = item.getElementsByTagName("input");  
    69.                     if (checkboxs != null) {  
    70.                       var checkbox = checkboxs[0];  
    71.                       if (!isSelected) {  
    72.                       checkbox.checked = true;  
    73.                       } else {  
    74.                       checkbox.checked = false;  
    75.                       }  
    76.                     }  
    77.                     }  
    78.                   }  
    79.                   },  
    80.                   queryMode : 'remote',  
    81.                   displayField : 'workstationName',  
    82.                   valueField : 'workstationIda',  
    83.                   }
    84.                   ]

    85.                         }]
    86.                       }, {
    87.                         title: 'B'
    88.                       }, {
    89.                         title: 'C'                    
    90.                       }, {
    91.                         title: 'D'                     
    92.                       }]
    93.                     })                 
    94.             }).show();

    95.         });
    96.   </script>
    97. </body>
    98. </html>
    复制代码
    效果:

    以上就是本文的全部内容,希望对大家学习javascript有所帮助。

    来源:互联网
    免责声明:如果侵犯了您的权益,请联系站长(1277306191@qq.com),我们会及时删除侵权内容,谢谢合作!

    本帖子中包含更多资源

    您需要 登录 才可以下载或查看,没有账号?立即注册

    ×

    最新评论

    QQ Archiver 手机版 小黑屋 福建二哥 ( 闽ICP备2022004717号|闽公网安备35052402000345号 )

    Powered by Discuz! X3.5 © 2001-2023

    快速回复 返回顶部 返回列表