Example of converting arbitrary Json to unordered list, and example of unordered json list

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.