如何使一些选定的项目在jstree中进行加载检查. (已选择=“已选择"无效)

问题描述:

在MVC 4中,我使用jstree.在创建操作中,我没有问题.但是在编辑"操作中,我将true值设置为treemodel的某些项.型号就像:

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;
}

当我填充树模型时,我将selected = true;设置为某些项目并在视图中使用它:

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"
                }
            },

但是在视图中,所有项目均未选中.我看到一些<li>标记具有selected = "selected",但这并不影响它的检查.

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

当我手动检查项目 时,jstree-unchecked更改为jstree-checked类.这意味着selected = "selected"不起作用.

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?

我找到了解决问题的方法.

I found solution for my question.

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