Невозможно установить для узла флажка jstree снятый флажок из JSON - PullRequest
1 голос
/ 17 марта 2011

Я не могу установить для CheckBox значение unchecked ["jstree-unchecked"] для узла, у которого есть дочерние элементы. Когда я использую firebug для определения класса узла на внешней стороне, он показывает «jstree-undefineded». Я действительно хочу, чтобы jstree-unchecked был классом, поскольку именно это я передаю с сервера.

Ниже приведен вызов AJAX, который я выполняю с использованием JSON. Я также добавил данные JSON, которые я получаю с сервера. Что-то не так в том, как я форматирую данные JSON на стороне сервера?
Для следующего примера узел "Dogs" вызывает проблему. Хотя дочерние элементы "Dogs" не проверены, а класс узла не проверен; Я вижу узел "Собаки" проверен. Любые советы по исправлению или улучшению кода приветствуются.

$(function () {
        $("#idTOC").bind("loaded.jstree", function (e, data) {
            data.inst.open_all(-1); // -1 opens all nodes in the container
        })
        .jstree({
            "json_data": {
                "ajax": {
                    "url": "http://localhost/eSiriusAjax/jqTOC.wc",
                    "aync": false,
                    "data": function (n) {
                        return { id: n.attr ? n.attr("id") : 0 };
                    }
                }
            },
            "core": { "html_titles": true },
            "themes": { "theme": "apple", "dots": false, "icons": false },
            "plugins": ["themes", "json_data", "checkbox"],
            "ui": { "select_limit": 1 }
        });

        $("#idTOC").bind('before.jstree', function (event, data) {
            if ((data.func === 'check_node') || (data.func === 'uncheck_node')) {
                event.stopImmediatePropagation(); //stops changing select/deselect when clicked
                return false;
            }
        });
    });

Данные JSON:

[
  {
    "data": "Intro",
    "attr": {
      "id": "1",
      "class": "jstree-checked",
      "href": "ProtocolIntro.aspx"
    }
  },
  {
    "data": "Overview",
    "attr": {
      "id": "3",
      "class": "jstree-unchecked",
      "href": "ProtocolOverview.aspx"
    }
  },
  {
    "data": "Funding",
    "attr": {
      "id": "5",
      "class": "jstree-checked"
    }
  },
  {
    "data": "Use TYPE(s)",
    "attr": {
      "id": "7",
      "class": "jstree-unchecked"
    }
  },
  {
    "data": "Transportation",
    "attr": {
      "id": "9",
      "class": "jstree-unchecked"
    }
  },
  {
    "data": "Dogs",
    "attr": {
      "id": "11",
      "class": "jstree-unchecked"
    },
    "children": [
      {
        "data": "Info",
        "attr": {
          "id": "12",
          "class": "jstree-unchecked"
        }
      },
      {
        "data": "# Justification",
        "attr": {
          "id": "13",
          "class": "jstree-unchecked"
        }
      },
      {
        "data": "Choice Justification",
        "attr": {
          "id": "14",
          "class": "jstree-unchecked"
        }
      },
      {
        "data": "Source",
        "attr": {
          "id": "15",
          "class": "jstree-unchecked"
        }
      },
      {
        "data": "Enrichment/Excercise",
        "attr": {
          "id": "16",
          "class": "jstree-unchecked"
        }
      },
      {
        "data": "Quarantine/Conditioning",
        "attr": {
          "id": "17",
          "class": "jstree-unchecked"
        }
      },
      {
        "data": "Housing",
        "attr": {
          "id": "18",
          "class": "jstree-unchecked"
        }
      },
      {
        "data": "Use Labs",
        "attr": {
          "id": "19",
          "class": "jstree-unchecked"
        }
      },
      {
        "data": "Surgery",
        "attr": {
          "id": "20",
          "class": "jstree-unchecked"
        }
      },
      {
        "data": "Procedures",
        "attr": {
          "id": "21",
          "class": "jstree-unchecked"
        }
      },
      {
        "data": "Euthanasia",
        "attr": {
          "id": "22",
          "class": "jstree-unchecked"
        }
      },
      {
        "data": "Methodology",
        "attr": {
          "id": "23",
          "class": "jstree-unchecked"
        }
      },
      {
        "data": "USDA Categories",
        "attr": {
          "id": "24",
          "class": "jstree-unchecked"
        }
      },
      {
        "data": "Adverse Consq.",
        "attr": {
          "id": "25",
          "class": "jstree-unchecked"
        }
      }
    ]
  },
  {
    "data": "Mice",
    "attr": {
      "id": "26",
      "class": "jstree-unchecked"
    },
    "children": [
      {
        "data": "Info",
        "attr": {
          "id": "27",
          "class": "jstree-unchecked"
        }
      },
      {
        "data": "# Justification",
        "attr": {
          "id": "28",
          "class": "jstree-unchecked"
        }
      },
      {
        "data": "Choice Justification",
        "attr": {
          "id": "29",
          "class": "jstree-unchecked"
        }
      },
      {
        "data": "Source",
        "attr": {
          "id": "30",
          "class": "jstree-unchecked"
        }
      },
      {
        "data": "Housing",
        "attr": {
          "id": "31",
          "class": "jstree-unchecked"
        }
      },
      {
        "data": "Use Labs",
        "attr": {
          "id": "32",
          "class": "jstree-unchecked"
        }
      },
      {
        "data": "Surgery",
        "attr": {
          "id": "33",
          "class": "jstree-checked",
          "href": "ProtocolSurgery.aspx"
        }
      },
      {
        "data": "Breeding",
        "attr": {
          "id": "34",
          "class": "jstree-unchecked"
        }
      },
      {
        "data": "Methodology",
        "attr": {
          "id": "35",
          "class": "jstree-unchecked"
        }
      },
      {
        "data": "USDA Categories",
        "attr": {
          "id": "36",
          "class": "jstree-unchecked"
        }
      },
      {
        "data": "Adverse Consq.",
        "attr": {
          "id": "37",
          "class": "jstree-unchecked"
        }
      }
    ]
  },
  {
    "data": "Personnel",
    "attr": {
      "id": "38",
      "class": "jstree-checked",
      "href": "ProtocolPersonnel.aspx"
    }
  },
  {
    "data": "Database Searches",
    "attr": {
      "id": "40",
      "class": "jstree-unchecked"
    }
  },
  {
    "data": "Error Verification",
    "attr": {
      "id": "42",
      "class": "jstree-unchecked"
    }
  },
  {
    "data": "Preview",
    "attr": {
      "id": "44",
      "class": "jstree-unchecked"
    }
  },
  {
    "data": "Cancel Un-finished Protocol",
    "attr": {
      "id": "46",
      "class": "jstree-unchecked"
    }
  }
]

Ответы [ 2 ]

1 голос
/ 05 апреля 2011

В данных JSON вместо class = "jstree-checked" можно отправить пользовательский атрибут, например, "checked": "true" |"флажок": "ложь".

Затем в запрос ajax добавьте обратный вызов complete , где вы проверяете все элементы, у которых установлен атрибут атрибута "true".*

0 голосов
/ 11 августа 2015

это работает для меня -

.bind("load_node.jstree", function (event, data) { 

                var productId = $("#Product_ProductId").val();
                if (!productId || productId < 1) {
                    data.inst.hide_checkboxes();
                } else
                    data.inst.change_state('li[selected=selected]', false);
            })

json data -

[{"data":{"title":"Electronics","icon":null},"metadata":{"id":3,"level":1,"leaf":false,"mapId":0},"state":"closed","attr":{"id":null,"rel":"folder","href":null,"selected":false},"children":[{"data":{"title":"Folder Name","icon":null},"metadata":{"id":28,"level":2,"leaf":true,"mapId":0},"state":"","attr":{"id":null,"rel":"default","href":null,"selected":false},"children":[{"data":{"title":"New Category","icon":null},"metadata":{"id":29,"level":3,"leaf":true,"mapId":0},"state":"","attr":{"id":null,"rel":"default","href":null,"selected":false},"children":[]}]},{"data":{"title":"Folder Name","icon":null},"metadata":{"id":30,"level":2,"leaf":false,"mapId":0},"state":"closed","attr":{"id":null,"rel":"folder","href":null,"selected":false},"children":[{"data":{"title":"File Name","icon":null},"metadata":{"id":31,"level":3,"leaf":false,"mapId":0},"state":"closed","attr":{"id":null,"rel":"folder","href":null,"selected":false},"children":[{"data":{"title":"File Name","icon":null},"metadata":{"id":32,"level":4,"leaf":true,"mapId":0},"state":"","attr":{"id":null,"rel":"default","href":null,"selected":false},"children":[]}]},{"data":{"title":"Folder Name","icon":null},"metadata":{"id":33,"level":3,"leaf":false,"mapId":0},"state":"closed","attr":{"id":null,"rel":"folder","href":null,"selected":false},"children":[{"data":{"title":"New Category","icon":null},"metadata":{"id":34,"level":4,"leaf":true,"mapId":13},"state":"","attr":{"id":null,"rel":"default","href":null,"selected":true},"children":[]}]}]}]},{"data":{"title":"Furniture","icon":null},"metadata":{"id":4,"level":1,"leaf":false,"mapId":0},"state":"closed","attr":{"id":null,"rel":"folder","href":null,"selected":false},"children":[{"data":{"title":"Folder Name","icon":null},"metadata":{"id":20,"level":2,"leaf":true,"mapId":0},"state":"","attr":{"id":null,"rel":"default","href":null,"selected":false},"children":[]},{"data":{"title":"File Name","icon":null},"metadata":{"id":22,"level":2,"leaf":true,"mapId":14},"state":"","attr":{"id":null,"rel":"default","href":null,"selected":true},"children":[]},{"data":{"title":"File Name","icon":null},"metadata":{"id":25,"level":2,"leaf":true,"mapId":0},"state":"","attr":{"id":null,"rel":"default","href":null,"selected":false},"children":[]},{"data":{"title":"Folder Name","icon":null},"metadata":{"id":26,"level":2,"leaf":true,"mapId":12},"state":"","attr":{"id":null,"rel":"default","href":null,"selected":true},"children":[]}]}]

добавить свойство selected в объект attr

...