JavaScript: Find all parents for element in tree recursive
问题 I have a tree somthing like this var datas = { 'tree': [ { 'name': 'name1', 'tree': [ {'name': 'name2'}, {'name': 'name3'}, { 'name': 'name4', 'tree': [ {'name': 'name5'}, {'name': 'name6'} ] }, {'name': 'name7'} ] }, { 'name': 'name8', 'tree': [ {'name': 'name9'} ] } ] } I want to find all the parents of the specifig id for example in the tree demo, if I look for 'name5' I want to find "name1,name4,name5" I wrote this code but the results wrong and I got the ids of other elements and not the