Search code examples
javascriptjsonbootstrap-treeview

Treeview - How to have nodes default checked in JSON?


For the jonmiles treeview plugin, how do I define in the json data that certain nodes are checked by default?

the following is completely ignored:

[{
        "text": "Parent 1",
        "checked": true,
        "nodes": [{
                "text": "Child 1",
                "nodes": [{
                        "text": "Grandchild 1"
                    },
                    {
                        "text": "Grandchild 2"
                    }
                ]
            },
            {
                "text": "Child 2"
            }
        ]
    },
    {
        "text": "Parent 2"
    },
    {
        "text": "Parent 3"
    },
    {
        "text": "Parent 4"
    },
    {
        "text": "Parent 5"
    }
]

Solution

  • It should work, if you use:

    {
        "text": "Parent 1",
        "state": {
            "checked": true
        }
    }
    

    You forgot to put the state property. For reference look at data structure in the readme.