Today I'm trying to put my front-end hat, and solve a little problem. I wrote an API that maps a directory tree and give me a JSON with the following structure:
{
"0": {
"children": [
{
"name": "still.txt",
"path": "/home/myname/docs/still.txt",
"type": "file"
},
{
"name": "now.txt",
"path": "/home/myname/docs/now.txt",
"type": "file"
},
{
"children": [
{
"name": "names.txt",
"path": "/home/myname/docs/other-docs/names.txt",
"type": "file"
},
{
"name": "places.txt",
"path": "/home/myname/docs/other-docs/places.txt",
"type": "file"
}
],
"name": "other-docs",
"path": "/home/myname/docs/other-docs",
"type": "directory"
},
{
"name": "address.txt",
"path": "/home/myname/docs/address.txt",
"type": "file"
}
],
"name": "",
"path": "/home/myname/docs",
"type": "directory"
}
}
This is a sample, but there may be infinite(large) nested directories.
This is how I think is done(sorry if it's stupid, I'm extremely new to jQuery):
<!DOCTYPE html>
<html>
<head>
<title>test</title>
<script src="jquery-3.2.1.min.js"></script>
<script>
$("#get_button").click(function(){
$.getJSON('http://192.168.200.77/api/', function(result){
$(result).each(function(i, result){
// Here something happens
$(content).appendTo("#files");
});
});
});
</script>
</head>
<body>
<h1>
Test Client
</h1>
<button id="get_button" type="button"> Get Tree </button>
<div id = "files"></div>
</body>
</html>
Is the request done in the right way? The API don't ask for data in the GET request.
I want to create a list of elements, with elements with id = "folder" for directories and id = "file" for files. How is it done?