在 JSTree 中禁用多项选择不起作用
Disable Multiple Selection in JSTree is not working
我在我的应用程序中使用 JSTree,代码如下。
this.CreateTreeView = function () {
$('#jstree_demo_div').jstree({
'core': {
'multiple': false,
'data': [
{ "id": "ajson1", "parent": "#", "text": "Simple root node" },
{ "id": "ajson2", "parent": "#", "text": "Root node 2" },
{ "id": "ajson3", "parent": "ajson2", "text": "Child 1" },
{ "id": "ajson4", "parent": "ajson2", "text": "Child 2" },
]
}
});
}
如我的代码所示,我正在尝试禁用多个 selection。
现在,当我对 select 节点使用以下代码时。
$("#jstree_demo_div").jstree().select_node("ajson3");
$("#jstree_demo_div").jstree().select_node("ajson4");
还是select这两个节点。所以它变成了来自 Javascript.
的多个 selection
我提出这个问题只是为了确认 JSTree 是否正确工作?
我知道我可以在 select 使用 deselect_all
函数删除任何节点之前删除 select 所有节点。
但根据我的说法,如果多个 selection 设置为 false,那么 selecting 来自 javascript 的节点也应该 select 只有一个节点。
如有错误请指正
select_node
将 select 一个节点,而不管 multiple
设置如何。
该设置仅限制用户交互,select_node
是较低级别的方法,不会受到限制,因此您(开发人员)可以无限制地以编程方式修改 selection。
如果您想使用由用户交互触发的相同功能(因此受到 multiple
的限制),请使用 activate_node
.
就用这个配置
this.CreateTreeView = function () {
**"plugins" : [
"checkbox",
],**
$('#jstree_demo_div').jstree({
'core': {
**'multiple': false,**
'data': [
{ "id": "ajson1", "parent": "#", "text": "Simple root node" },
{ "id": "ajson2", "parent": "#", "text": "Root node 2" },
{ "id": "ajson3", "parent": "ajson2", "text": "Child 1" },
{ "id": "ajson4", "parent": "ajson2", "text": "Child 2" },
]
},
**'checkbox' : {
'deselect_all': true,
'three_state' : false,
}**
}); }
'checkbox' : {
'deselect_all': true,
'three_state' : false,
}
工作正常!
要在 JStree 中禁用多复选框select,此代码也可以完美运行:
var tmp=null; /// to prevent recursion
treeobj.on("check_node.jstree uncheck_node.jstree", function(e, data) {
if(tmp!=data.node.id){
tmp=data.node.id;
treeobj.jstree("uncheck_all", null);
treeobj.jstree("check_node",data.node.id);
}
})
我在我的应用程序中使用 JSTree,代码如下。
this.CreateTreeView = function () {
$('#jstree_demo_div').jstree({
'core': {
'multiple': false,
'data': [
{ "id": "ajson1", "parent": "#", "text": "Simple root node" },
{ "id": "ajson2", "parent": "#", "text": "Root node 2" },
{ "id": "ajson3", "parent": "ajson2", "text": "Child 1" },
{ "id": "ajson4", "parent": "ajson2", "text": "Child 2" },
]
}
});
}
如我的代码所示,我正在尝试禁用多个 selection。
现在,当我对 select 节点使用以下代码时。
$("#jstree_demo_div").jstree().select_node("ajson3");
$("#jstree_demo_div").jstree().select_node("ajson4");
还是select这两个节点。所以它变成了来自 Javascript.
的多个 selection我提出这个问题只是为了确认 JSTree 是否正确工作?
我知道我可以在 select 使用 deselect_all
函数删除任何节点之前删除 select 所有节点。
但根据我的说法,如果多个 selection 设置为 false,那么 selecting 来自 javascript 的节点也应该 select 只有一个节点。
如有错误请指正
select_node
将 select 一个节点,而不管 multiple
设置如何。
该设置仅限制用户交互,select_node
是较低级别的方法,不会受到限制,因此您(开发人员)可以无限制地以编程方式修改 selection。
如果您想使用由用户交互触发的相同功能(因此受到 multiple
的限制),请使用 activate_node
.
就用这个配置
this.CreateTreeView = function () {
**"plugins" : [
"checkbox",
],**
$('#jstree_demo_div').jstree({
'core': {
**'multiple': false,**
'data': [
{ "id": "ajson1", "parent": "#", "text": "Simple root node" },
{ "id": "ajson2", "parent": "#", "text": "Root node 2" },
{ "id": "ajson3", "parent": "ajson2", "text": "Child 1" },
{ "id": "ajson4", "parent": "ajson2", "text": "Child 2" },
]
},
**'checkbox' : {
'deselect_all': true,
'three_state' : false,
}**
}); }
'checkbox' : {
'deselect_all': true,
'three_state' : false,
}
工作正常!
要在 JStree 中禁用多复选框select,此代码也可以完美运行:
var tmp=null; /// to prevent recursion
treeobj.on("check_node.jstree uncheck_node.jstree", function(e, data) {
if(tmp!=data.node.id){
tmp=data.node.id;
treeobj.jstree("uncheck_all", null);
treeobj.jstree("check_node",data.node.id);
}
})