Jquery EasyUI Combotree只能選擇葉子節點且葉子節點有多選框node
Jquery EasyUI Combotree單選框,Jquery EasyUI Combotree只能選擇葉子節點ui
EasyUI Combotree葉子節點增長單選框this
================================spa
©Copyright 蕃薯耀 2018年4月28日blog
http://www.cnblogs.com/fanshuyao/ip
建議使用方式三(完美版)get
1、方式一,最簡單(只能單選葉子節點,葉子節點前面無多選框)string
- $("xxxId").combotree({
- data : [{……},{……},{……}],
- required: false,
- onBeforeSelect : function(node){
- if(!$(this).tree("isLeaf", node.target)){
- return false;
- }
- }
- });
2、方式二:控制只能選一項,選中某一項後後面不能再勾選(體驗比較生硬)it
- $("xxxId").combotree({
- multiple : true,
- data : [{……},{……},{……}],
- required: false,
- checkbox : true,
- onlyLeafCheck : true,
- onBeforeSelect : function(node){
- if(!$(this).tree("isLeaf", node.target)){
- return false;
- }
- },
- onBeforeCheck : function(node, checked){
- if(checked){
- var nodes = $(this).tree("getChecked");
-
- if(nodes.length == 0){
- return true;
- }else{
- return false;
- }
- }else{
- return true;
- }
- }
- });
3、方式三:隨意選擇任意一項,但只能選一項(完美版)io
- $("xxxId").combotree({
- multiple : true,
- data : [{……},{……},{……}],
- required: false,
- checkbox : true,
- onlyLeafCheck : true,
- onBeforeSelect : function(node){
- $(this).tree("check", node.target);
- return false;
- },
- onBeforeCheck : function(node, checked){
- if(checked){
- var nodes = $(this).tree("getChecked");
-
- if(nodes.length > 0){
- for(var i=0; i<nodes.length; i++){
- $(this).tree("uncheck", nodes[i].target);
- }
- }
- }
- }
- });
方法三中:onBeforeSelect方法返回false,避免第一次點擊文字選中後,再從新打開選擇,不點擊文字,直接勾選多選框,第一次點擊的文字有黃色背景的狀況,以下:
================================
©Copyright 蕃薯耀 2018年4月28日
http://www.cnblogs.com/fanshuyao/