• <center id="sm46c"></center>
  • <dfn id="sm46c"></dfn>
  • <strike id="sm46c"></strike>
  • <cite id="sm46c"><source id="sm46c"></source></cite>
    • <strike id="sm46c"><source id="sm46c"></source></strike>
      <option id="sm46c"></option>
      国产精品天天看天天狠,女高中生强奷系列在线播放,久久无码免费的a毛片大全,国产日韩综合av在线,亚洲国产中文综合专区在,特殊重囗味sm在线观看无码,中文字幕一区二区三区四区在线,无码任你躁久久久久久老妇蜜桃

      根據(jù)json文件生成動態(tài)菜單

      2018-5-31    seo達人

      如果您想訂閱本博客內(nèi)容,每天自動發(fā)到您的郵箱中, 請點這里

      [plain] view plain copy
      1. <span style="font-family:SimSun;font-size:16px;">admin.json</span>  
      [plain] view plain copy
      1. <span style="font-family:SimSun;font-size:16px;">[  
      2.     {  
      3.         "image": "glyphicon glyphicon-home",//菜單前的圖標(biāo)  
      4.         "name": "設(shè)備管理",  
      5.         "submenu": [  
      6.             {  
      7.                 "image": "glyphicon glyphicon-cloud",  
      8.                 "name": "設(shè)備分類",  
      9.                 "submenu": [  
      10.                     {  
      11.                         "image": "glyphicon glyphicon-off",  
      12.                         "name": "電源管理",  
      13.                         "url": "html/Node/creditCardPower.html"  
      14.                     },  
      15.                     {  
      16.                             "image": "glyphicon glyphicon-lock",  
      17.                         "name": "門禁管理",  
      18.                         "url": "html/Guard/guardList.html"  
      19.                     },  
      20.                     {  
      21.                         "image": "glyphicon glyphicon-folder-open",  
      22.                         "name": "物品管理",  
      23.                         "url": "html/goods/goodsList.html"  
      24.                     },  
      25.                     {  
      26.                         "image": "glyphicon glyphicon-facetime-video",  
      27.                         "name": "視頻管理",  
      28.                         "url": "html/monitor/monitorList.html"  
      29.                     }  
      30.                 ]  
      31.             }  
      32.         ]  
      33.     },  
      34.     {  
      35.         "image": "glyphicon glyphicon-cog",  
      36.         "name": "系統(tǒng)設(shè)置",  
      37.         "submenu": [  
      38.             {  
      39.                 "image": "glyphicon glyphicon-heart",  
      40.                 "name": "用戶管理",  
      41.                 "submenu": [  
      42.                     {  
      43.                         "image": "glyphicon glyphicon-align-justify",  
      44.                         "name": "用戶列表",  
      45.                         "url": "html/User/userList.html"  
      46.                     },  
      47.                     {  
      48.                         "image": "glyphicon glyphicon-random",  
      49.                         "name": "組織機構(gòu)",  
      50.                         "url": "html/dept/framework.html"  
      51.                     }  
      52.                 ]  
      53.             },  
      54.             {  
      55.                 "image": "glyphicon glyphicon-wrench",  
      56.                 "name": "設(shè)備管理",  
      57.                 "submenu": [  
      58.                     {  
      59.                         "image": "glyphicon glyphicon-edit",  
      60.                         "name": "設(shè)備參數(shù)",  
      61.                         "url": "html/Device/DeviceList.html"  
      62.                     },  
      63.                     {  
      64.                         "image": "glyphicon glyphicon-edit",  
      65.                         "name": "物品庫",  
      66.                         "url": "html/equgoods/equGoodsList.html"  
      67.                     }  
      68.                 ]  
      69.             }  
      70.         ]  
      71.     },  
      72.     {  
      73.         "image": "glyphicon glyphicon-list",  
      74.         "name": "日志管理",  
      75.         "submenu": [  
      76.             {  
      77.                 "image": "glyphicon glyphicon-list-alt",  
      78.                 "name": "登入日志",  
      79.                 "url": "html/Log/loginlog.html"  
      80.             },  
      81.             {  
      82.                 "image": "glyphicon glyphicon-tag",  
      83.                 "name": "設(shè)備日志",  
      84.                 "url": "html/Log/hardwarelog.html"  
      85.             }  
      86.         ]  
      87.     },  
      88.     {  
      89.         "image":"glyphicon glyphicon-list",  
      90.         "name":"設(shè)備管理",  
      91.         "submenu":[  
      92.             {  
      93.             "image":"glyphicon glyphicon-list-alt",  
      94.             "name":"設(shè)備管理",  
      95.             "url":"html/mechanism/mechanism.html"  
      96.             }  
      97.         ]  
      98.     }  
      99. ]</span>  

      2、讀取json文件的service層實現(xiàn)

      [java] view plain copy
      1. <span style="font-size:16px;">package com.dskj.service.impl;  
      2.   
      3. import java.io.File;  
      4. import java.util.Scanner;  
      5. import org.springframework.beans.factory.annotation.Value;  
      6. import org.springframework.core.io.Resource;  
      7. import org.springframework.stereotype.Service;  
      8.   
      9. import com.dskj.common.util.StringUtil;  
      10. import com.dskj.service.ReadJsonService;  
      11.   
      12. @Service  
      13. public class ReadJsonServiceImpl implements ReadJsonService{  
      14.     <span style="color:#ff0000;">@Value(value="classpath:json/admin.json")</span>  
      15.     private Resource dataAdmin;      
      16.     <span style="color:#ff0000;">@Value(value="classpath:json/user.json")</span>  
      17.     private Resource dataUser;    
      18.       
      19.     public String getData(String fileName){       
      20.         if(StringUtil.isEmpty(fileName)){  
      21.             throw new NullPointerException();  
      22.         }  
      23.           
      24.         String jsonData = null;  
      25.           
      26.         try {  
      27.             File file = null;     if(fileName.equals("admin.json")){  
      28.                 file = dataAdmin.getFile();  
      29.             }else{  
      30.                 file = dataUser.getFile();  
      31.             }  
      32.               
      33.             jsonData = this.jsonRead(file);  
      34.               
      35.         } catch (Exception e) {  
      36.            e.printStackTrace();  
      37.         }    
      38.         return jsonData;         
      39.     }  
      40.     /** 
      41.      * 讀取文件類容為字符串 
      42.      * @param file 
      43.      * @return 
      44.      */  
      45.       private String jsonRead(File file){  
      46.             Scanner scanner = null;  
      47.             StringBuilder buffer = new StringBuilder();  
      48.             try {  
      49.                 scanner = new Scanner(file, "utf-8");  
      50.                 while (scanner.hasNextLine()) {  
      51.                     buffer.append(scanner.nextLine());  
      52.                 }  
      53.             } catch (Exception e) {  
      54.                   
      55.             } finally {  
      56.                 if (scanner != null) {  
      57.                     scanner.close();  
      58.                 }  
      59.             }  
      60.             return buffer.toString();  
      61.         }  
      62. }</span>  

      3、controller對應(yīng)的代碼片段

      [java] view plain copy
      1. <span style="font-size:16px;">@RequestMapping("")  
      2.     public ModelAndView main() {  
      3.         ModelAndView model = null;  
      4.         String jsonFileName = null;  
      5.           
      6.         SysUser currentUser = (SysUser) ContextUtil.getSession().getAttribute("currentUser");  
      7.         if ("admin".equals(currentUser.getUsername())) {  
      8.             model = new ModelAndView("header1");  
      9.             jsonFileName = "<span style="color:#ff0000;">admin.json</span>";//根據(jù)文件名判斷讀取具體json文件  
      10.         } else {  
      11.             model = new ModelAndView("headerUser");  
      12.             jsonFileName = "<span style="color:#ff0000;">user.json</span>";</span>/<span style="font-size:16px;">/根據(jù)文件名判斷讀取具體json文件  
      13.   
      14.         }  
      15.           
      16.         String menue = <span style="color:#3333ff;">readJsonServiceImpl.getData</span>(jsonFileName);  
      17.           
      18.         model.addObject("menue", menue);  
      19.         return model;  
      20.   
      21.     }</span>  

      4、html頁面 將jsonarray轉(zhuǎn)換成js對象

      [javascript] view plain copy
      1. <span style="font-size:16px;">$(function() {  
      2.     var menue = JSON.parse('<span style="color:#ff0000;"><%=request.getAttribute("menue")%></span>');  
      3.     console.info(menue);  
      4.     createMenu(menue);//調(diào)用下邊的方法生成動態(tài)菜單</span>  

      5、對js對象遍歷 $.append動態(tài)添加到對應(yīng)頁面

      [javascript] view plain copy
      1. <span style="font-size:16px;">function createMenu(menue){  
      2.             /* 一級菜單 */  
      3.             $.each(menue,function(i,v){  
      4.                 var menu1 = '<li class="active"><a href="javaScript:;">';  
      5.                 /* menu1 += '<span class="glyphicon glyphicon-home"></span>'; */  
      6.                 menu1 += '<span class=' + '\'' + v.image + '\'' + '>' + '</span>';  
      7.                 menu1 += '<span style="margin-left: 10px;">' + v.name + '</span><span class="fa arrow"></span>';  
      8.                 menu1 += '</a>';  
      9.                 menu1 += '<ul class="nav nav-second-level nps collapse in">';  
      10.                   
      11.                  /* 二級菜單  */  
      12.                     $.each(v.submenu,function(j,vJ){                      
      13.                         var menu2 = '<li class="active">';  
      14.                         menu2 +=        '<a href="javaScript:;" class="">';  
      15.                         /* menu2 +=         '<span class="glyphicon glyphicon-cloud" style="margin-right: 10px;"></span>'; */  
      16.                         menu2 +=            '<span class=' + '\'' + vJ.image + '\'' + 'style=' + '\'' + 'margin-right: 10px;' + '\'' + '>' + '</span>';  
      17.                         menu2 +=             vJ.name + '<span class="fa arrow "></span>';  
      18.                         menu2 +=        '</a>';  
      19.                         menu2 +=                '<ul class="nav nav-third-level nps collapse in">';                             
      20.                               
      21.                         /* 三級菜單 */  
      22.                         if(vJ.submenu){  
      23.                             $.each(vJ.submenu,function(k,vk){  
      24.                                 var menu3 = '<li>';  
      25.                                 menu3 +=        '<a href="javascript:openUrl(\'' + vk.url + '\')">';  
      26.                                 /* menu3 +=             '<span style="margin-right: 10px;" class="glyphicon glyphicon-off">'; */  
      27.                                 menu3 +=            '<span stype=' + '\'' + 'margin-right: 10px;' + '\'' + 'class=' + '\'' + vk.image + '\'' + '';  
      28.                                 menu3 +=            '</span>'+vk.name;  
      29.                                 menu3 +=        '</a>';  
      30.                                 menu3 +=    '</li>';  
      31.                                   
      32.                                 menu2 += menu3;  
      33.                                       
      34.                             });  
      35.                         }else{  
      36.                             $.each(v.submenu,function(j,vJ){  
      37.                                 var menu4 = '<li>';  
      38.                                 menu4 +=        '<a href="javascript:openUrl(\'' + vJ.url + '\')">';  
      39.                                 /* menu3 +=             '<span style="margin-right: 10px;" class="glyphicon glyphicon-off">'; */  
      40.                                 menu4 +=            '<span stype=' + '\'' + 'margin-right: 10px;' + '\'' + 'class=' + '\'' + vJ.image + '\'' + '';  
      41.                                 menu4 +=            '</span>'+vJ.name;  
      42.                                 menu4 +=        '</a>';  
      43.                                 menu4 +=    '</li>';  
      44.                                       
      45.                                  menu2 = menu4;   
      46.                             });  
      47.                         }  
      48.                             menu1 += menu2;  
      49.                     });  
      50.                       
      51.                     $("#side-menu").append(menu1);  
      52.                 });  
      53.                   
      54.             }</span>  

      6、效果如下圖

      藍藍設(shè)計www.li-bodun.cn )是一家專注而深入的界面設(shè)計公司,為期望卓越的國內(nèi)外企業(yè)提供卓越的UI界面設(shè)計、BS界面設(shè)計 、 cs界面設(shè)計 、 ipad界面設(shè)計 、 包裝設(shè)計 、 圖標(biāo)定制 、 用戶體驗 、交互設(shè)計、 網(wǎng)站建設(shè) 平面設(shè)計服務(wù)

      日歷

      鏈接

      個人資料

      藍藍設(shè)計的小編 http://www.li-bodun.cn

      存檔

      主站蜘蛛池模板: 香蕉国产人午夜视频在线观看| 久久嫩草影院免费看| 久久99精品无码一区二区三区| 日韩精品中文字幕无码一区| AV在线亚洲欧洲日产一区二区| 久久久久成人精品无码中文字幕| 久久天堂无码av网站| 久久精品国产88精品久久| 亚洲综合无码明星蕉在线视频 | 久久国产精品娇妻素人| av中文无码韩国亚洲色偷偷| 亚洲另类无码一区二区三区| 国产对白熟女受不了了| 色妺妺在线视频喷水| 级毛片免费看无码| 开平市| 亚洲午夜性猛春交XXXX| 米奇777超碰欧美日韩亚洲 | 日本中文一区二区三区亚洲| 国产对白老熟女正在播放| 亚洲综合一区二区三区视频| 中文字幕亚洲无线码A| 日韩在线永久免费播放| 亚洲AV日韩AV不卡在线观看| 亚洲精品美女一区二区| 鲁丝无码一区二区三区| 久久婷婷五月综合尤物色国产| 国产成人精品无码免费看| 亚洲色大成网站WWW永久麻豆| 嫩草研究院久久久精品| 亚洲AV秘 无码一区二区三区臀| 屯留县| 国产成人亚洲欧美激情| 搡老妇女老熟女一区二区| 中文字幕有码日韩精品| 四虎国产精品免费久久久| 国产精品福利自产拍久久| 中文字幕永久在线看| 亚洲精品拍拍央视网出文| 又色又爽又黄的视频网站| 亚洲中文字幕亚洲中文精|