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:;
-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)' //这是我本地测试的颜色 可以略过
});
}
});
}

bootstrap-treeview 在 bootstrap 4 不兼容解决办法及使用的更多相关文章

  1. IE6/IE7下margin-bottom失效兼容解决办法及双倍边距问题

    (从已经死了一次又一次终于挂掉的百度空间人工抢救出来的,发表日期 2014-04-08) 一.IE6/IE7下margin-bottom失效兼容解决办法 1.用padding-bottom代替:2.在 ...

  2. bootstrap顶部导航遮挡下面内容的解决办法

    使用bootstrap设置顶部导航,并将导航栏固定,代码如下: <nav class="navbar navbar-expand-lg navbar-light bg-light fi ...

  3. 关于Vue.cli 脚手架环境中引入Bootstrap时,table表格样式缺失的解决办法

    Vue+bootstrap不能正常使用table的样式 环境:下载官网的本地bootstrap包,然后在vue 的index.html引入bootstrap的css和js环境 问题描述:1. vue里 ...

  4. IOS中input键盘事件keyup 的兼容解决办法

    用input监听键盘keyup事件,在安卓手机浏览器中是可以的,但是在ios手机浏览器中很慢,用输入法输入之后,并未立刻相应keyup事件. 解决办法: 在ios设备上可以用html5的input事件 ...

  5. js date 火狐不兼容 解决办法 火狐版本25,0

    <!DOCTYPE HTML> <html lang="en-US"> <head> <meta charset="UTF-8& ...

  6. Bootstrap之Carousel不能自动播放的解决办法(转)

    Bootstrap是一个非常好的css/javaScript框架,尤其对于移动端的自适应和适配能力都比较强. 用Bootstrap自带的Carousel写了一个图片轮播的广告部分,用js调用后却出现了 ...

  7. bootstrap 下拉菜单不显示的解决办法

    bootstrap 下拉菜单不显示,最后改成如下正常显示: <div class="btn-group open"> <ul class="dropdo ...

  8. bootstrap图标字体不出来问题的解决办法

    @font-face { font-family: 'Glyphicons Halflings'; src: url('/Scripts/bootstrap/fonts/glyphicons-half ...

  9. EXT3.0在IE下Range不兼容解决办法

    采用EXT3.0创建一个提示框,IE9下显示异常.经过资料查询,发现添加如下代码即可解决问题. // 这段代码是为了兼容IE if ((typeof Range !== "undefined ...

随机推荐

  1. [Swift]LeetCode221. 最大正方形 | Maximal Square

    Given a 2D binary matrix filled with 0's and 1's, find the largest square containing only 1's and re ...

  2. [Swift]LeetCode385. 迷你语法分析器 | Mini Parser

    Given a nested list of integers represented as a string, implement a parser to deserialize it. Each ...

  3. [Swift]LeetCode658. 找到 K 个最接近的元素 | Find K Closest Elements

    Given a sorted array, two integers k and x, find the kclosest elements to x in the array. The result ...

  4. [Swift]LeetCode1000. 合并石头的最低成本 | Minimum Cost to Merge Stones

    There are N piles of stones arranged in a row.  The i-th pile has stones[i] stones. A move consists ...

  5. [Swift]LeetCode1026. 节点与其祖先之间的最大差值 | Maximum Difference Between Node and Ancestor

    Given the root of a binary tree, find the maximum value V for which there exists different nodes A a ...

  6. Redis基本使用及百亿数据量中的使用技巧分享(附视频地址及观看指南)

    作者:依乐祝 原文地址:https://www.cnblogs.com/yilezhu/p/9941208.html 主讲人:大石头 时间:2018-11-10 晚上20:00 地点:钉钉群(组织代码 ...

  7. vue+cordova构建跨平台应用集成并使用Cordova plugin

    安装 //安装 vue-cil npm install --global vue-cli //安装cordova npm i cordova -g cordova 新建项目 //新建cordova 项 ...

  8. 如何判断DataSet里有多少个DataTable

    dataset.table.count sda.fill(ds,"table"); //这里是在ds里新建了一个表,叫table,注意是新建,多次执行会报错,实际使用时,可以用co ...

  9. glusterfs+heketi为k8s提供共享存储

    背景 近来在研究k8s,学习到pv.pvc .storageclass的时候,自己捣腾的时候使用nfs手工提供pv的方式,看到官方文档大量文档都是使用storageclass来定义一个后端存储服务, ...

  10. 设计模式总结篇系列:享元模式(Flyweight)

    我们都知道,Java中的String类具有如下特性:String是一个不可变类,当直通过用字符串方式使用String对象时,Jvm实际上在内存中只存有一份,且存在字符串常量池中.当对字符串直接进行修改 ...