Jquery tree traversal - Nested Unordered list elements to JSON

后端 未结 3 1874
深忆病人
深忆病人 2020-12-18 10:52

Okay, Now I have an unordered list here:

  • Item A
3条回答
  •  盖世英雄少女心
    2020-12-18 11:28

    Ah, a fun little recursive exercise. I had a moment for this and here’s how I would do it. This works many levels deep recursively, but assumes that your data is not deep enough to explode the memory (recursion breaks in browsers if it is too deep). Should be fine for at least 10 levels or so.

    I tested this out, seems it works, just save this in a HTML file and you should be fine.

    Sorry there are not too many comments (well, technically speaking, none at all :) , this assumes you read jQuery and JS code fine. If you have questions, just ask in a comment and I’d be happy to explain.

    
    
    
        
        Recursive list processor example
        
        
    
    
    
    
    
    

提交回复
热议问题