Example of converting arbitrary Json to unordered list, and example of unordered json list
Preface
I don't know if you have found that many tree plug-ins on the Internet require fixed Json format, but you didn't consider this when generating Json, so you can only splice strings to generate Unordered Lists.
For example:
{"Top menu 1": [{"domain": "top menu 1", "runType": "background", "moduleName": "sub menu", "memo ": "Description", "srcFile": "", "depends": []}], "top menu 2": [{"domain": "top menu 2 ", "runType": "background", "moduleName": "sub-menu 1", "memo": "Description", "srcFile": "", "depends ": []}, {"domain": "top menu 2", "runType": "background", "moduleName": "sub menu 2", "memo ": "Description", "srcFile": "", "depends": []}], "top menu 3": []}
Paste Code directly...
dataObject = JSON.parse(data);var html = '<ul>';var domainName;var moduleName;for ( var n in dataObject) { html += '<li>' + n + '<ul class="listItem">'; for (var i = 0; i < dataObject[n].length; i++) { domainName=dataObject[n][i].domain; moduleName=dataObject[n][i].moduleName; html += '<a href="#">' + '<li>'+ moduleName + '</li>'+ '</a>'; } html += '</ul></li>';}html += '</ul>';$('#sidebar').append(html);
Summary
The above is all about this article. I hope this article will help you in your study or work. If you have any questions, please leave a message.