【问题标题】:JsTree 3.2.1 checkbox issuesJsTree 3.2.1 复选框问题
【发布时间】:2016-01-12 15:25:53
【问题描述】:

我正在使用延迟加载的 jstre 3.2.1,一切正常。 这是我在 asp.net mvc5 操作中填写的 Json 类。

public class AutorisationNodeModel
    {
        public int id { get; set; }
        public string text { get; set; }
        public List<AutorisationNodeModel> children { get; set; }
        public State state { get; set; }
    }

    public class State
    {
        public bool selected { get; set; }
    }

和视图

$("#AutorizationTree").jstree({
            "core": {
                "themes": {
                    "responsive": false
                },
                // so that create works
                "check_callback": true,
                'data': {
                    "type": "POST",
                    "dataType": "json",
                    'url': function (node) {
                        return '@Url.Action("GetTreeNodes", "Administration")';
                    },
                    'data': function (node) {
                        return { 'IdApplication': $('#AppSelectionne').val() };
                    }
                }
            },
            "types": {
                "default": {
                    "icon": "fa fa-folder icon-state-success icon-lg"
                },
                "file": {
                    "icon": "fa fa-file icon-state-success icon-lg"
                }
            },
            "plugins": ["dnd", "types", "checkbox", "json_data"],
            "checkbox": { "tie_selection": false }

        });

但预先选择的节点无法正常工作,请帮我解决这个问题

【问题讨论】:

  • 你为什么要设置"tie_selection": false?
  • 我找到了一个将“tie_selection”设置为 false 的示例

标签: asp.net-mvc jstree


【解决方案1】:

要在初始加载时预先选择节点,您需要以这种方式在节点配置中具有 state 属性:

{
  "id": "nodeid",
  "text": "somestring",
  "state": { "selected": true }
}

检查您从服务器获取的内容并提供给 jsTree。另外我不明白你在用这个代码做什么:return { 'IdApplication': $('#AppSelectionne').val() };。但是如果你想在下载后将state属性添加到json中,你可以试试:return { 'IdApplication': $('#AppSelectionne').val(), 'state': { 'selected': true } };。

【讨论】:

  • return { 'IdApplication': $('#AppSelectionne').val() };用于获取节点的子树。
  • 这是来自服务器的 json 结果
  • [{"id":1,"text":"Chapitre","children":[{"id":2,"text":"Affecter Programme","children":null ,"state":{"selected" :true}},{"id":3,"text":"Désaffecter Programme","children":null,"state":{"selected":true}},{ "id":4,"text":"Consulter Chapitre","children":null,"state":{"selected":true}},{"id":5,"text":"Vérifier les mesures" ]
  • 一切就绪。不用"tie_selection": false 可以试试吗?
  • 我在这个 url jsfiddle.net/DGAF4/161 中尝试了一个带有最少代码的示例示例,但它不起作用我认为 jstree 版本有问题
猜你喜欢
  • 2012-01-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多