how to convert json to bootstrap treeview format
var data = {
"title": "Person",
"type": "object",
"properties": {
"firstName": {
"type": "string"
},
"lastName": {
"type": "string"
},
"age": {
"description": "Age in years",
"type": "integer",
"minimum": 0
}
},
"required": ["firstName", "lastName"]
};
$(document).ready(function() {
function format_for_treeview(data, arr) {
for (var key in data) {
if (Array.isArray(data[key]) || data[key].toString() === "[object Object]") {
// when data[key] is an array or object
var nodes = [];
var completedNodes = format_for_treeview(data[key], nodes);
arr.push({
text: key,
nodes: completedNodes
});
} else {
// when data[key] is just strings or integer values
arr.push({
text: key + " : " + data[key]
});
}
}
return arr;
}
$("#my-treeview").treeview({
color: "#428bca",
expandIcon: "glyphicon glyphicon-stop",
collapseIcon: "glyphicon glyphicon-unchecked",
showTags: true,
data: format_for_treeview(data, [])
});
});
Also in JavaScript:
- javascript how to get subarray
- set a value in session using javascript
- react state array push
- json in listview flutter
- how to create object js
- javascript return a random value from an array
- jquery don't empty specific form field after submit
- map with async
- dice roller javascript
- js reload page 1024 breakpoint
- react Spread Attributes conditionally
- calculate rating out of 5
- print("Google") in JavaScript
- angular http get status code
- shadow elevation react native
- npm update package.json version field by code
- javascript null or object
- javascript break foreach
- get the name of month without using hard coded arrays in javascript
- checking if var is not defined js
- graphql react filtering
- nodejs current timestamp
- create eventlistener to close webpage js
- react native flatlist margin bottom