search

Home  >  Q&A  >  body text

javascript - How to select the node corresponding to the attribute structure and obtain the corresponding id and parent id

The information returned by the tree structure is as follows. When selected, "state": {"selected" : true} will be generated accordingly. Now I want to get the corresponding id when selected and the id of the parent. How to solve it elegantly? ?


[
    {
        "id": "514600710075631001",
        "text": "医院管理",
        "state": {
            "selected": true
        },
        "children": [
            {
                "id": "514600710075631106",
                "text": "职称管理",
                "state": {
                    "selected": true
                },
                "children": [
                    {
                        "id": "514600710075631151",
                        "text": "职称列表"
                    }
                ]
            },
            {
                "id": "514600710075631102",
                "text": "科室管理",
                "children": [
                    {
                        "id": "514600710075631121",
                        "text": "科室列表"
                    }
                ]
            }
        ]
    }
]

Similar to Demo http://css-tricks.com/example...

淡淡烟草味淡淡烟草味2807 days ago537

reply all(1)I'll reply

  • 仅有的幸福

    仅有的幸福2017-05-19 10:31:19

    If you are directly manipulating the DOM, use the parentNode,如果是框架操作 DOM 则为每个点维护一个 parent attribute.

    Or, don’t change anything, bind events to all nodes, and the bubbling mechanism will automatically traverse it.

    reply
    0
  • Cancelreply