Javascript 在JSTree中禁用多个选择不起作用
我正在我的应用程序中使用JSTree,代码如下Javascript 在JSTree中禁用多个选择不起作用,javascript,jquery,jstree,Javascript,Jquery,Jstree,我正在我的应用程序中使用JSTree,代码如下 this.CreateTreeView = function () { $('#jstree_demo_div').jstree({ 'core': { 'multiple': false, 'data': [ { "id": "ajson1", "parent": "#", "text": "Simple root node" },
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" },
]
}
});
}
如我的代码所示,我正在尝试禁用多重选择
现在,当我使用以下代码选择节点时
$("#jstree_demo_div").jstree().select_node("ajson3");
$("#jstree_demo_div").jstree().select_node("ajson4");
仍然选择两个节点。因此,它就像来自Javascript的多重选择
我提出这个问题只是为了确认JSTree的工作是否正确?
我知道我可以在使用deselect\u all
功能选择任何节点之前取消选择所有节点
但根据我的说法,如果multiple selection设置为false,那么从javascript中选择节点也应该只选择一个节点
如果我错了,请更正。
选择节点
将选择一个节点,而不考虑多个
设置
该设置仅限制用户交互,select\u node
是较低级别的方法,不会受到限制,因此您(开发人员)可以通过编程方式修改选择,而不受限制
如果您想使用由用户交互触发的相同功能(因此受到多个
的限制),请使用activate\u 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,
}**
}); }
很好 要禁用JStree中的复选框multi-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非常好。
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);
}
})