A simple solution for displaying check-boxes in hierarchical tree structures (i.e. a Tree View) with Amazing Bootstrap.
Include the following files in your project.
- bootree.min.css
- bootree.min.js
Add the following resources in your html file.
<!-- Required Stylesheets -->
<link href="../dist/bootree.min.css" rel="stylesheet" type="text/css" />
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<!-- Required Javascript -->
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<script src="../dist/bootree.min.js" type="text/javascript"></script>
The component will bind to any existing DOM element.
<div id="tree"></div>
To initialize the BooTree and plot the check-boxes in #tree:
<script type="text/javascript">
$(document).ready(function () {
var tree = $('#tree').tree({
primaryKey: 'id',
uiLibrary: 'bootstrap',
dataSource: [ { id: 1, text: 'Apple', children: [ { id: 2, text: 'Avocado' } ] } ]
checkboxes: true
});
$('#btnSave').on('click', function () {
var checkedIds = tree.getCheckedNodes();
alert(checkedIds);
});
});
</script>
You can see BooTree here.