繁体   English   中英

使用flare.json文件在HTML中构造嵌套的无序列表?

[英]Construct nested unordered list in HTML using flare.json file?

如何将以下flare.json文件构造为HTML中的嵌套无序列表? 我打算使用嵌套的无序列表来显示图表。

有人可以指导我如何转换吗?

{
    "name": "flare",
    "children": [
        {
            "name": "analytics",
            "children": [
                {
                    "name": "cluster",
                    "children": [
                        {"name": "AgglomerativeCluster", "size": 3938},
                        {"name": "CommunityStructure", "size": 3812},
                        {"name": "HierarchicalCluster", "size": 6714},
                        {"name": "MergeEdge", "size": 743}
                    ]
                },
                {
                    "name": "graph",
                    "children": [
                        {"name": "BetweennessCentrality", "size": 3534},
                        {"name": "LinkDistance", "size": 5731},
                        {"name": "MaxFlowMinCut", "size": 7840},
                        {"name": "ShortestPaths", "size": 5914},
                        {"name": "SpanningTree", "size": 3416}
                    ]
                },
                {
                    "name": "optimization",
                    "children": [
                        {"name": "AspectRatioBanker", "size": 7074}
                    ]
                }
            ]
        }
    ]
}

您的问题有些含糊,但这是我的问题。 让我知道这不是您想要的东西。

以下是相关代码:

function pprint(o) {
  if(typeof o != 'object') {
    return o.toString(); /* Note: this check won't work for javascript in general, but should be okay for the result of JSON.parse */
  }
  var open = '<ul>', close = '</ul>', html = '', notArray = true;
  if(Array.isArray(o)) {
    open = '<ol>';
    close = '</ol>';
    notArray = false;
  }
  $.each(o, function(k,v){
    html += '<li>';
    if(notArray) {
      html += k+': ';
    }
    html += pprint(v)+'</li>';
  });
  return open+html+close;
}

演示在这里: http : //codepen.io/devm33/pen/lspjh/

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM