【问题标题】:How to make some selected items as checked on load in jstree. (selected = "selected" not working)如何在 jstree 中使某些选定项目在加载时被选中。 (选择=“选择”不工作)
【发布时间】:2013-07-08 05:17:28
【问题描述】:

在 MVC 4 中,我使用 jstree。在创建操作中我没有问题。但在编辑操作中,我将true 值设置为treemodel 的某些项。模型是这样的:

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; 设置为一些项目并在视图中使用它:

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

但在视图中,所有项目都未选中。我看到一些&lt;li&gt; 标签有selected = "selected",但这并不影响它的检查。

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

我该如何解决这个问题?

【问题讨论】:

    标签: javascript jquery tree jstree treemodel


    【解决方案1】:

    我找到了问题的解决方案。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-06-23
      • 1970-01-01
      • 2019-06-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-28
      相关资源
      最近更新 更多