easyUI menu动态添加

来源:岁月联盟 编辑:exp 时间:2012-05-23

HTML代码:

[html] <!-- 菜单 --> 
          <div id="mm" class="easyui-menu" style="width:140px;">   
       
            </div>   
<!-- 菜单 -->
       <div id="mm" class="easyui-menu" style="width:140px;"> 
     
            </div> 


Javascript代码:

[javascript] /*绑定右键*/ 
                 $(".datagrid-cell").live('contextmenu',function(e){//.datagrid-cell 是easyUI表格样式,这样设置的原因是,让菜单在表格上点击右键才显示  
                  var selectRow=$('#grid').datagrid('getSelected');//获得选中行数据  
                     //显示快捷菜单  
                     if(selectRow==null){ 
                      Ext.Msg.alert('提示', '请在表格上单击左键选择一行数据.'); 
                      return false; 
                     } 
                     //第一步将集合清空  
                     $('#mm').empty(); 
                     //创建菜单  
                     createMenu(selectRow); 
                    // alert($('#mm').children().size());  
                     //没有子菜单,那么不显示  
                     if($('#mm').children().size()==0){ 
                         return false; 
                     } 
                   //菜单添加完毕显示菜单  
                     $('#mm').menu('show', { 
                         left: e.pageX, 
                         top: e.pageY 
                     }); 
                     return false; 
                 }); 
/*绑定右键*/
                 $(".datagrid-cell").live('contextmenu',function(e){//.datagrid-cell 是easyUI表格样式,这样设置的原因是,让菜单在表格上点击右键才显示
                  var selectRow=$('#grid').datagrid('getSelected');//获得选中行数据
                     //显示快捷菜单
                     if(selectRow==null){
                      Ext.Msg.alert('提示', '请在表格上单击左键选择一行数据.');
                      return false;
                     }
                     //第一步将集合清空
                     $('#mm').empty();
                     //创建菜单
                     createMenu(selectRow);
                    // alert($('#mm').children().size());
                     //没有子菜单,那么不显示
                     if($('#mm').children().size()==0){
                      return false;
                     }
                   //菜单添加完毕显示菜单
                     $('#mm').menu('show', {
                         left: e.pageX,
                         top: e.pageY
                     });
                     return false;
                 });

 

创建菜单方法:

[javascript] //创建菜单  
               function createMenu(row){ 
                    var tjlx = document.getElementById("tjlx").value; // 统计类型   年1  季度2  月3  日4  
                    var collectType=document.getElementById("collectType").value;//统计方式  unit:按单位 Sections 按科室  
                    var orgcode=row.orgcode; 
                    var showtime=row.showtime; 
                    var collectType=document.getElementById("collectType").value;//unit,按单位;Sections,按科室  
                    var officecode=""; 
                    if(collectType=='Sections'){ 
                           var officecode=row.officecode; 
                    } 
                    //if 01  
                        if(collectType=="unit"){ 
                var dbyear=showtime.substring(0,4);//年度  
                var exaTimeType="0"; 
                if(tjlx=="2"){ 
                var exaTimeType=showtime.substring(showtime.indexOf("年")+1,showtime.indexOf("季"));//季度  
                } 
                if(tjlx=="3"){ 
                var exaTimeType=showtime.substring(showtime.indexOf("年")+1,showtime.indexOf("月"));//月份  
                } 
                 //绑定点击事件  
                  $('#mm').menu('appendItem',{id:"m_001",text:"按日期各科室分解"}); 
                  $("#m_001").click(function(){ 
                     openWin(orgcode,dbyear,tjlx,exaTimeType,officecode,"Sections"); 
                  }); 
                } 
                    //if 01  
                      //if 02  
                        if(tjlx=="1"){ 
                    var dbyear=showtime.substring(0,4);//年度  
                    //添加点击事件,onclick:  
                     $('#mm').menu('appendItem',{id:"m_002",text:"按日期各季度分解"}); 
                     $("#m_002").click(function(){ 
                         openWin(orgcode,dbyear,"2","0",officecode,collectType); 
                      }); 
                } 
                      //if 02  
                       
                      //if 03  
                        //年 按照月度查询  
                if(tjlx=="1") 
                { 
                var dbyear=showtime.substring(0,4);//年度  
                //添加点击事件,onclick:  
                $('#mm').menu('appendItem',{id:"m_003",text:"按日期各月份分解"}); 
                $("#m_003").click(function(){ 
                    openWin(orgcode,dbyear,"3","0",officecode,collectType); 
                  }); 
                } 
                      //if 03  
                       
                      //if 04  
                      //季度按照月查询 www.2cto.com   
                if(tjlx=="2"){   
                var dbyear=showtime.substring(0,4);//年度  
                var exaTimeType=showtime.substring(showtime.indexOf("年")+1,showtime.indexOf("季"));//季度  
                    var tempExaTimeType=""; 
                    if(exaTimeType=="1") 
                    { 
                        tempExaTimeType="1,2,3"; 
                    } 
                    if(exaTimeType=="2") 
                    { 
                        tempExaTimeType="4,5,6"; 
                    } 
                    if(exaTimeType=="3") 
                    { 
                        tempExaTimeType="7,8,9"; 
                    } 
                    if(exaTimeType=="4") 
                    { 
                        tempExaTimeType="10,11,12"; 
                    } 
                    //添加点击事件,onclick:  
                    $('#mm').menu('appendItem',{id:"m_004",text:"按日期各月份分解"}); 
                    $("#m_004").click(function(){ 
                        openWin(orgcode,dbyear,"3",tempExaTimeType,officecode,collectType); 
                      }); 
                } 
                      //if 04  
                         
                     
               } 
                
  //创建菜单
                 function createMenu(row){
                     var tjlx = document.getElementById("tjlx").value; // 统计类型   年1  季度2  月3  日4
                  var collectType=document.getElementById("collectType").value;//统计方式  unit:按单位 Sections 按科室
                  var orgcode=row.orgcode;
                  var showtime=row.showtime;
                  var collectType=document.getElementById("collectType").value;//unit,按单位;Sections,按科室
                  var officecode="";
                  if(collectType=='Sections'){
                      var officecode=row.officecode;
                  }
                  //if 01
                  if(collectType=="unit"){
      var dbyear=showtime.substring(0,4);//年度
      var exaTimeType="0";
      if(tjlx=="2"){
      var exaTimeType=showtime.substring(showtime.indexOf("年")+1,showtime.indexOf("季"));//季度
      }
      if(tjlx=="3"){
      var exaTimeType=showtime.substring(showtime.indexOf("年")+1,showtime.indexOf("月"));//月份
      }
          //绑定点击事件
        $('#mm').menu('appendItem',{id:"m_001",text:"按日期各科室分解"});
           $("#m_001").click(function(){
           openWin(orgcode,dbyear,tjlx,exaTimeType,officecode,"Sections");
           });
      }
                  //if 01
                        //if 02
                        if(tjlx=="1"){
       var dbyear=showtime.substring(0,4);//年度
       //添加点击事件,onclick:
        $('#mm').menu('appendItem',{id:"m_002",text:"按日期各季度分解"});
        $("#m_002").click(function(){
         openWin(orgcode,dbyear,"2","0",officecode,collectType);
            });
      }
                        //if 02
                       
                        //if 03
                         //年 按照月度查询
      if(tjlx=="1")
      {
      var dbyear=showtime.substring(0,4);//年度
      //添加点击事件,onclick:
      $('#mm').menu('appendItem',{id:"m_003",text:"按日期各月份分解"});
      $("#m_003").click(function(){
       openWin(orgcode,dbyear,"3","0",officecode,collectType);
           });
      }
                        //if 03
                       
                        //if 04
                        //季度按照月查询
      if(tjlx=="2"){ 
      var dbyear=showtime.substring(0,4);//年度
      var exaTimeType=showtime.substring(showtime.indexOf("年")+1,showtime.indexOf("季"));//季度
          var tempExaTimeType="";
       if(exaTimeType=="1")
       {
        tempExaTimeType="1,2,3";
       }
       if(exaTimeType=="2")
       {
        tempExaTimeType="4,5,6";
       }
       if(exaTimeType=="3")
       {
        tempExaTimeType="7,8,9";
       }
       if(exaTimeType=="4")
       {
        tempExaTimeType="10,11,12";
       }
       //添加点击事件,onclick:
       $('#mm').menu('appendItem',{id:"m_004",text:"按日期各月份分解"});
       $("#m_004").click(function(){
        openWin(orgcode,dbyear,"3",tempExaTimeType,officecode,collectType);
            });
      }
                        //if 04
                     
                  
                 }
                

 

 

摘自 yhc13429826359的专栏