Loop to a filesystem structure in my object to get all the files

后端 未结 4 1445
孤独总比滥情好
孤独总比滥情好 2021-01-17 01:16

I get a Javascript Object from my server, which depicts a filesystem. Now I want to get the path of all files in the system, e.g. the endpoints of the tree.

File str

4条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-17 01:33

    working solution:

    var json = {"path":"/pages/services/project", "is_dir":true, "children":[{"path":"/pages/services/project/headline","is_dir":false,"children":[]},{"path":"/pages/services/project/text","is_dir":false,"children":[]},
    {"path":"/pages/services/project/test/","is_dir":true,"children":[{"path":"/pages/services/project/test/text","is_dir":false,"children":[]},
    {"path":"/pages/services/project/test/picture","is_dir":false,"children":[]}]}]};
    
    json.children.forEach(function (child) {
        goToDeepestPoint(child);
    });
    
    
    
    function goToDeepestPoint(node) {
        if (node.is_dir){
          for(var i=0;i

提交回复
热议问题