Using jstree some tree nodes do not display

When using jstree to build a system menu button tree, you want to present the following effect:

Results after the first level node is opened, the child nodes are not displayed. Click once, all the nodes are gone, and there are no errors on the page and background. It's really weird.

Because it is the background string json string to the foreground, I printed the following data in the console:

[
                {
                    "id": "1",
                    "text": "Authority authentication system",
                    "children": [
                        {
                            "id": "1",
                            "text": "user management ",
                            "children": [
                                {
                                    "id": "1",
                                    "text": "Test 1"
                                }
                            ]
                        },
                        {
                            "id": "2",
                            "text": "Role management",
                            "children": [
                                {
                                    "id": "2",
                                    "text": "Test 2"
                                }
                            ]
                        },
                        {
                            "id": "3",
                            "text": "Dictionary management",
                            "children": [
                                {
                                    "id": "3",
                                    "text": "Test 3"
                                }
                            ]
                        },
                        {
                            "id": "4",
                            "text": "system management",
                            "children": [
                                {
                                    "id": "4",
                                    "text": "Test 4"
                                }
                            ],
                        }
                    ]
                }
            ];

It completely conforms to the format of json. Later, I changed the field order and quotation marks, which is useless. Finally, it was found that the id was repeated. It was thought that the node id of the same layer would not be repeated, but it was found that the id of all nodes could not be repeated. Add a prefix to the nodes of different layers, and the problem will be solved.

By the way: jstree can only recognize json strings composed of id, text, children and other names.

Tags: JSON

Posted on Sat, 02 May 2020 07:24:28 -0700 by fean0r