zoukankan      html  css  js  c++  java
  • bootstrap-treeview 在 bootstrap 4 不兼容解决办法及使用

    bootstrap-treeview 是bootstrap的一个树形插件,插件依赖:

    bootstrap/3.3.7
    jquery/3.3.1

    经过验证,它不可以在 bootstrap 高于 3.3.7 版本中使用,当前 treeview 的版本为 bootstrap-treeview/1.2.0  ,  bootstrap/3.3.7

    <link href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
    <script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script>
    <script src="https://cdn.bootcss.com/bootstrap-treeview/1.2.0/bootstrap-treeview.min.js"></script>

    其实它这个不兼容是因为这个插件用了 版本3 的图标,而 bootstrap 4 却把这些图标给干掉了,因此需要手动添加这些图标文件 Glyphicons.scss:

    @charset 'utf-8';
    
    at-root {
      // Import the fonts
      @font-face {
          font-family: 'Glyphicons Halflings';
          src:  url('../font/bootstrap/glyphicons-halflings-regular.eot');
          src:  url('../font/bootstrap/glyphicons-halflings-regular.eot') format('embedded-opentype'),
            url('../font/bootstrap/glyphicons-halflings-regular.ttf') format('truetype'),
            url('../font/bootstrap/glyphicons-halflings-regular.woff') format('woff'),
            url('../font/bootstrap/glyphicons-halflings-regular.woff2') format('woff2'),
            url('../font/bootstrap/glyphicons-halflings-regular.svg') format('svg');
          font-weight: normal;
          font-style: normal;
      }
    }
    
    // Catchall baseclass
    .glyphicon {
      position: relative;
      top: 1px;
      display: inline-block;
      font-family: 'Glyphicons Halflings';
      font-style: normal;
      font-weight: normal;
      line-height: 1;
      -webkit-font-smoothing: antialiased;
      -moz-osx-font-smoothing: grayscale;
    }

    bootstrap 3 国内打不开不了,这是个英文版,需要翻墙:https://getbootstrap.com/docs/3.3/getting-started/ 去下载。

    在html中,只写一个存放的文件树的容器即可:

    <div id="tree"></div>

    假定先做一个假数据,使用 tree.json:

    [
      {
        "text":"Bakersfield office",
        "nodes": [
          {
            "text":"Bakersfield BD"
          },
          {
            "text":"Bakersfield marketing"
          },
          {
              "text":"Bakersfield HR"
          }
        ]
      },
      {
        "text":"Stockton office",
        "nodes": [
                {
                    "text":"Stockton  service"
                },
                {
                    "text":"Stockton After sales"
                },
                {
                    "text":"Stockton Field service"
                },
                {
                    "text":"Stockton Finance"
                },
                {
                    "text":"Stockton HR"
                }
        ]
      },
      {
        "text":"Chesapeake office HR"
      }
    ]               

    然后使用 ajax 将数据填入 #tree 的容器中:

    function getTree(){
      var url = 'http://127.0.0.1:8020/localhost-cloudClocking-CMS/js/tree.json';
           
            $.ajax({
                type:"get",
                url:url,
                dataType: 'json',
                contentType: 'application/json; charset=utf-8',
                success: function(data) {
                        console.log(data);
                        $('#tree').treeview({
                            levels: 1,
                            data:data,
                            selectedBackColor: 'rgba(#000000,.12)' //这是我本地测试的颜色 可以略过
                        });
                }
        });      
    }

  • 相关阅读:
    SQL注入攻击
    新手指引,php什么是常量、变量、数组、类和对象及方法?
    JQuery坑,说说哪些大家都踩过的坑
    利用Jsonp实现跨域请求,spring MVC+JQuery
    【实用】需要收藏备用的JQuery代码片段
    【动画】JQuery实现冒泡排序算法动画演示
    【基础】26个命令玩转linux,菜鸟及面试必备
    【收藏】8段JQuery处理表单的代码片段,很实用
    【实用】Html5实现文件异步上传
    【基础】新手任务,五分钟全面掌握JQuery选择器
  • 原文地址:https://www.cnblogs.com/baiyygynui/p/9396071.html
Copyright © 2011-2022 走看看