I am using:
我在用:
jstree("disable_node", "#" + NodeID);
to disable a node in jstree. and using:
禁用jstree中的节点。和使用:
jstree("enable_node", "#" + NodeID);
to enable a node.
启用节点。
Is there a simple way to disable/enable
a node and it's children?
是否有一种简单的方法可以禁用/启用节点及其子节点?
thank you
谢谢
2 个解决方案
#1
2
You can do it with the code as below. Check demo - Fiddle.
您可以使用以下代码执行此操作。检查演示 - 小提琴。
-
Write a recursive function to iterate multi-level structures
编写递归函数来迭代多级结构
function changeStatus(node_id, changeTo) { var node = $("#tree").jstree().get_node(node_id); if (changeTo === 'enable') { $("#tree").jstree().enable_node(node); node.children.forEach(function(child_id) { changeStatus(child_id, changeTo); }) } else { $("#tree").jstree().disable_node(node); node.children.forEach(function(child_id) { changeStatus(child_id, changeTo); }) } }
-
Call function depending on what you need
根据您的需要调用函数
changeStatus(NodeID, 'enable');
or
要么
changeStatus(NodeID, 'disable');
#2
2
I write a simple JS function based on jstree
documentation about get_node
function and jstree
JSON data format that enable/disable
the input node and all it's child in any level:
我编写了一个基于jstree文档的简单JS函数,该文档关于get_node函数和jstree JSON数据格式,它启用/禁用输入节点及其在任何级别的所有子节点:
NodeToggleEnable = function (node_id, enable) {
var tree = $("#jstree-locations");
var sub_tree = [node_id.toString()];
var index = 0;
while (index < children.length) {
var child = tree.jstree("get_node", "#" + children[index]).children;
sub_tree = sub_tree.concat(child);
if (enable == false)
tree.jstree("disable_node", "#" + sub_tree[index]);
else
tree.jstree("enable_node", "#" + sub_tree[index]);
index++;
}
}
this function uses children
(array of strings or objects) property of node that selected by get_node
function.
此函数使用由get_node函数选择的节点的子节点(字符串或对象的数组)属性。
#1
2
You can do it with the code as below. Check demo - Fiddle.
您可以使用以下代码执行此操作。检查演示 - 小提琴。
-
Write a recursive function to iterate multi-level structures
编写递归函数来迭代多级结构
function changeStatus(node_id, changeTo) { var node = $("#tree").jstree().get_node(node_id); if (changeTo === 'enable') { $("#tree").jstree().enable_node(node); node.children.forEach(function(child_id) { changeStatus(child_id, changeTo); }) } else { $("#tree").jstree().disable_node(node); node.children.forEach(function(child_id) { changeStatus(child_id, changeTo); }) } }
-
Call function depending on what you need
根据您的需要调用函数
changeStatus(NodeID, 'enable');
or
要么
changeStatus(NodeID, 'disable');
#2
2
I write a simple JS function based on jstree
documentation about get_node
function and jstree
JSON data format that enable/disable
the input node and all it's child in any level:
我编写了一个基于jstree文档的简单JS函数,该文档关于get_node函数和jstree JSON数据格式,它启用/禁用输入节点及其在任何级别的所有子节点:
NodeToggleEnable = function (node_id, enable) {
var tree = $("#jstree-locations");
var sub_tree = [node_id.toString()];
var index = 0;
while (index < children.length) {
var child = tree.jstree("get_node", "#" + children[index]).children;
sub_tree = sub_tree.concat(child);
if (enable == false)
tree.jstree("disable_node", "#" + sub_tree[index]);
else
tree.jstree("enable_node", "#" + sub_tree[index]);
index++;
}
}
this function uses children
(array of strings or objects) property of node that selected by get_node
function.
此函数使用由get_node函数选择的节点的子节点(字符串或对象的数组)属性。