Question

In MVC 4 i use jstree. In create operation I have not problem. But in Edit operation, I set true value to some items of treemodel. models are like:

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 fill tree model, i set selected = true; to some items and use this in view:

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

But in view, all items are unchecked. I see some <li> tags have selected = "selected", but this does not affect it's checking.

When I check item manually, jstree-unchecked changes to jstree-checked class. It means that selected = "selected" does not work.

enter image description here

How can I solve this issue?

Was it helpful?

Solution

I found solution for my question.

.bind("loaded.jstree", function (event, data) {
    $('li[selected=selected]').each(function () {
        $(this).removeClass('jstree-unchecked').addClass('jstree-checked');
    });
});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top