How to make some selected items as checked on load in jstree. (selected = “selected” not working)

我怕爱的太早我们不能终老 提交于 2019-12-25 01:45:21

问题


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.

How can I solve this issue?


回答1:


I found solution for my question.

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


来源:https://stackoverflow.com/questions/17519593/how-to-make-some-selected-items-as-checked-on-load-in-jstree-selected-selec

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!