在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" },
]
}
});
}
如我的代码所示,我正在尝试禁用多选。
现在,当我使用以下代码来选择节点时。
$("#jstree_demo_div").jstree().select_node("ajson3");
$("#jstree_demo_div").jstree().select_node("ajson4");
它仍然选择两个节点。因此,它变得像是从Javascript中进行多选。
我提出这个问题只是为了确认JSTree的工作是否正确
我知道在使用deselect_all
函数选择任何节点之前,我可以取消选择所有节点。
但根据我的说法,如果多选设置为false,那么从javascript中选择节点也应该只选择一个节点。
如果我错了,请纠正我。
select_node
将选择一个节点,而不考虑multiple
的设置。
该设置仅限制用户交互,select_node
是一种较低级别的方法,不会受到限制,因此您(开发人员(可以通过编程方式无限制地修改选择。
如果您想使用由用户交互触发的相同功能(因此受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中的复选框多选,此代码也可以完美工作:
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);
}
})
相关文章:
- electronic BrowserWindow的最小高度和宽度在hide()show()方法之后不起作用
- 监视函数从服务返回不起作用,但作用域函数起作用
- 幻灯片滚动javascript不起作用
- 简单的javascript在Shopify中不起作用
- Recaptcha在IE7和IE8中不起作用
- Ember Data DS.Model's set函数不起作用
- JsFiddle上的鼠标事件不起作用
- 我的AngularJS表达式没有'不起作用
- 点击按钮输入不起作用
- 面向对象的Javascript代码在IE7中不起作用
- 分部隐藏在jquery中不起作用
- 在phonegap应用程序内部重定向不起作用
- Array.length似乎不起作用;console.log则显示其他情况
- $ionicplatform内的$scope不;不起作用
- 我的javascript for循环不起作用
- Meteor-添加用户自定义字段的方法不起作用
- 为什么 .focus() 不起作用,而 .css(“color”,“red”) 在同一个选择器上起作用
- jstree拖放不起作用
- jsTree create_node回调函数不起作用
- 在JSTree中禁用多选不起作用