Turning nested JSON into an HTML nested list with Javascript

后端 未结 3 1900
忘了有多久
忘了有多久 2021-02-06 13:03

I\'m fairly new to using JSON (as opposed to XML) and am currently working purely with Javascript to digest, parse and display my returned JSON data.

I\'m using the JSON

3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-02-06 13:32

    Your json is unsuited to your task. Some objects have several properties with the same name ("node"), so they are overriding one another. You have to use arrays of nodes instead. Here is a working data structure and the functions that can turn it into a nested list:

    
    
    
    
    
    
    
        
    
    
    

    And I can add this css to have the items numberings match the node titles :)

    
    

    See it in action.

提交回复
热议问题