BootStrap TreeView使用实例详解

前端之家收集整理的这篇文章主要介绍了BootStrap TreeView使用实例详解前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

本文实例为大家分享了BootStrap TreeView使用代码,供大家参考,具体内容如下

<script src="/Scripts/bootstrap/js/jquery.js" type="text/javascript"&gt;</script>

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

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

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

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

});

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

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

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

})

})

弹窗口+树形菜单的具体代码

<script src="/Scripts/bootstrap/js/jquery.js" type="text/javascript"&gt;</script> <script src="/Scripts/bootstrap/js/bootstrap.js" type="text/javascript"&gt;</script>

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

<p id="c">

<button class="btn btn-primary btn-lg" data-toggle="modal"
data-target="#myModal">
开始演示模态框

<div class="modal fade" id="myModal" tabindex="-1" role="dialog"
aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close"
data-dismiss="modal" aria-hidden="true">
×

<script type="text/javascript">
$(function () {
function getTree() {
// Some logic to retrieve,multiSelect: true

});

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

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


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

})

})

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持编程之家。

猜你在找的Bootstrap相关文章