首頁  >  文章  >  web前端  >  實例詳解BootStrap TreeView使用方法

實例詳解BootStrap TreeView使用方法

PHPz
PHPz原創
2018-05-14 14:56:064673瀏覽

本文主要為大家詳細介紹了BootStrap TreeView使用實例,具有一定的參考價值,有興趣的小夥伴們可以參考一下,希望能幫助大家。

【相關影片推薦:Bootstrap教學

<html>
<head>
  <title></title>
    <link href="/Scripts/bootstrap/css/bootstrap.css" rel="stylesheet">
   <link href="/Scripts/bootstrap/css/bootstrap-treeview.css" rel="stylesheet">

    <script src="/Scripts/bootstrap/js/jquery.js" type="text/javascript"></script>
   <script src="/Scripts/bootstrap/js/bootstrap-treeview.js" type="text/javascript"></script>

</head>
<body>
<p id="tree"></p>

<input type="button" id="btn" value="查询" />

<script type="text/javascript">
  $(function () {
    function getTree() {
      // Some logic to retrieve, or generate tree structure


      var data = [{
        text: "p1",
        nodes: [{ text: "p1-1", id: &#39;00001&#39;, nodeId: &#39;00001&#39; }, { text: "p1-2", id: &#39;00002&#39; }, { text: "p1-3", id: &#39;00003&#39; }, { text: "p1-4", id: &#39;00004&#39;, nodes: [{ text: &#39;p1-1-1&#39;, id: &#39;00005&#39;}]}]

      }]
      return data;
    }
    var obj = {};
    obj.text = "123";
    $(&#39;#tree&#39;).treeview({
      data: getTree(),     // data is not optional
      levels: 5,
      multiSelect: true

    });

    $("#btn").click(function (e) {

      var arr = $(&#39;#tree&#39;).treeview(&#39;getSelected&#39;);

      alert(JSON.stringify(arr));
      for (var key in arr) {
        alert(arr[key].id);
      }

    })

  })
  
</script>
</body>
</html>

彈視窗+樹狀選單的具體程式碼

<html>
<head>
  <title></title>
      <link href="/Scripts/bootstrap/css/bootstrap.css" rel="stylesheet">
   <link href="/Scripts/bootstrap/css/bootstrap-treeview.css" rel="stylesheet">

    <script src="/Scripts/bootstrap/js/jquery.js" type="text/javascript"></script>
    <script src="/Scripts/bootstrap/js/bootstrap.js" type="text/javascript"></script>
   <script src="/Scripts/bootstrap/js/bootstrap-treeview.js" type="text/javascript"></script>
</head>
<body>

<p id="c"></p>

<!-- 按钮触发模态框 -->
<button class="btn btn-primary btn-lg" data-toggle="modal" 
  data-target="#myModal">
  开始演示模态框
</button>

<!-- 模态框(Modal) -->
<p class="modal fade" id="myModal" tabindex="-1" role="dialog" 
  aria-labelledby="myModalLabel" aria-hidden="true">
  <p class="modal-dialog">
   <p class="modal-content">
     <p class="modal-header">
      <button type="button" class="close" 
        data-dismiss="modal" aria-hidden="true">
         ×
      </button>
      <h4 class="modal-title" id="myModalLabel">
        模态框(Modal)标题
      </h4>
     </p>
     <p class="modal-body">
     <p id="tree"></p>
     </p>
     <p class="modal-footer">
      <button type="button" class="btn btn-default" 
        data-dismiss="modal">关闭
      </button>
      <button type="button" class="btn btn-primary" id="btn">
        提交更改
      </button>
     </p>
   </p><!-- /.modal-content -->
</p><!-- /.modal -->
</p>

<script type="text/javascript">
  $(function () {
    function getTree() {
      // Some logic to retrieve, or generate tree structure


      var data = [{
        text: "p1",
        nodes: [{ text: "p1-1", id: &#39;00001&#39;, nodeId: &#39;00001&#39; }, { text: "p1-2", id: &#39;00002&#39; }, { text: "p1-3", id: &#39;00003&#39; }, { text: "p1-4", id: &#39;00004&#39;, nodes: [{ text: &#39;p1-1-1&#39;, id: &#39;00005&#39;}]}]

      }]
      return data;
    }
    var obj = {};
    obj.text = "123";
    $(&#39;#tree&#39;).treeview({
      data: getTree(),     // data is not optional
      levels: 5,
      multiSelect: true

    });

    $("#btn").click(function (e) {

      var arr = $(&#39;#tree&#39;).treeview(&#39;getSelected&#39;);


      for (var key in arr) {
        c.innerHTML = c.innerHTML + "," + arr[key].id;
      }

    })

  })
  
</script>
</body>
</html>

相關推薦:

bootstrap中外掛程式treeview的介紹與使用

jQuery TreeView樹形控制項之資料支援json字串、list集合

JS控制TreeView的結點選擇

#

以上是實例詳解BootStrap TreeView使用方法的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn