How to make some selected items checked when loading in jstree. (selected = "selected" does not work)

In MVC 4, I am using jstree. In the create operation, I have no problem. But in the editing operation, I set the value truefor some treemodel elements. models are similar to:

public class RecursiveObject
{             
    public string data { get; set; }
    public Int64 id { get; set; }  
    public FlatTreeAttribute attr { get; set; }
    public List<RecursiveObject> children { get; set; }
}

public class FlatTreeAttribute
{
    public string id;
    public bool selected;
}

When I populate the tree model, I set selected = true;for some elements and use this in the view:

json_data: {
                "ajax": {
                    url: "@Url.Action("GetTreeData", "MyController")",
                    type: "POST",
                    dataType: "json",
                    contentType: "application/json charset=utf-8"
                }
            },

However, all items are not marked. I see that the tags <li>have selected = "selected", but this does not affect the validation.

When I check the item manually , jstree-uncheckedit goes into the class jstree-checked. This means that selected = "selected"does not work.

enter image description here

How can I solve this problem?

0
1

.

.bind("loaded.jstree", function (event, data) {
    $('li[selected=selected]').each(function () {
        $(this).removeClass('jstree-unchecked').addClass('jstree-checked');
    });
});
+1

Source: https://habr.com/ru/post/1736427/


All Articles