Bootstrap-treeview 不会展开或折叠

Pla*_*Pro 4 bootstrap-treeview

这是我的 html 文件。

 <head>
       <meta charset="utf-8" />
       <meta http-equiv="X-UA-Compatible" content="IE=edge">
       <title>Pimba na Bulita</title>
       <meta name="viewport" content="width=device-width, initial-scale=1.0"/>

       <!-- FontAwesome -->
        <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.0.13/css/all.css" integrity="sha384-DNOHZ68U8hZfKXOrtjWvjxusGo9WQnrNx2sqG0tfsghAvtVlRW3tvkXWZh58N9jp" crossorigin="anonymous">

       <!-- Bootstrap -->
       <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" integrity="sha384-WskhaSGFgHYWDcbwN70/dfYBj47jz9qbsMId/iRN3ewGhXQFZCSftd1LZCfmhktB" crossorigin="anonymous"/>

       <!-- My custom Css -->
       <link rel="stylesheet" type="text/css" media="screen" href="assets/css/main.css" /> 

       <!-- TreeView -->
       <link rel="stylesheet" type="text/css" href="assets/bootstrap-treeview/dist/bootstrap-treeview.min.css">
    </head>
    <body>
       <div class="col-md-6" align="center">            
          <span>List of Recent records</span>
          <div id="tree"></div>
       </div>  
        <!-- JQUERY -->
        <script src="https://code.jquery.com/jquery-3.3.1.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8="
         crossorigin="anonymous"></script>

        <!-- Bootstrap JS -->
        <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js" integrity="sha384-smHYKdLADwkXOn1EmN1qk/HfnUcbVRZyYmZ4qpPea6sjB/pTJ0euyQp0Mk8ck+5T" crossorigin="anonymous"></script>  


         <!-- TreeView -->
         <script src="./assets/bootstrap-treeview/dist/bootstrap- 
         treeview.min.js"></script>
    </body>
Run Code Online (Sandbox Code Playgroud)

这是我的 js 文件,我在其中初始化了 bootstrap-treeview。

$(document).ready(function() {
    var tree = [
      {
        text: "Parent 1",
        nodes: [
          {
            text: "Child 1",
            nodes: [
              {
                text: "Grandchild 1"
              },
              {
                text: "Grandchild 2"
              }
            ]
          },
          {
            text: "Child 2"
          }
        ]
      },
      {
        text: "Parent 2"
      },
      {
        text: "Parent 3"
      },
      {
        text: "Parent 4"
      },
      {
        text: "Parent 5"
      }
    ];

    $('#tree').treeview({data: tree});
});
Run Code Online (Sandbox Code Playgroud)

正如你们在下面看到的那样。问题是:由于某种原因,无法展开/折叠树。

详细信息:如果我从文件中删除了 css 引用。它没有任何区别! 在此处输入图片说明

为什么会发生这种情况以及如何解决?

小智 5

问题似乎源于Bootstrap4 放弃了 Glyphicons 字体。我的解决方法是在项目的github上编辑developer分支的bootstrap-treeview.js文件,使得36-42行指定的默认图标如下:

expandIcon: 'fa fa-plus-square-o',
collapseIcon: 'fa fa-minus-square-o',
emptyIcon: '',
nodeIcon: '',
selectedIcon: '',
checkedIcon: 'fa-check-square-o',
uncheckedIcon: 'fa fa-square-o',
Run Code Online (Sandbox Code Playgroud)

确保链接到应用程序中的fontawesome5 CDN

  • 对于最新版本的 fontawesome 图标已更改。如果您尝试应用此修复程序,请确保检查他们的类名现在是什么 (2认同)