EasyUI Forum
September 13, 2025, 09:55:04 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: how can i get combotree(with checkbox) value according to check order  (Read 13237 times)
joker
Newbie
*
Posts: 17


View Profile Email
« on: November 06, 2015, 04:37:52 AM »

Hi,all
   I am using combotree with checkbox,when i want to get it's values, I find it's values is a array according to tree order,
how can i get  it's values according to user check order. Thanks.
Logged
jarry
Administrator
Hero Member
*****
Posts: 2298


View Profile Email
« Reply #1 on: November 06, 2015, 07:34:05 PM »

You have to reorder the values after check or select a node from the drop-down panel. Please refer to the code below:
Code:
$('#cc').combotree({
multiple: true,
cascadeCheck: false,
onClick: function(node){
clickNode($('#cc'), node.id);
},
onCheck: function(node, checked){
clickNode($('#cc'), node.id);
}
});
function clickNode(cc, id){
var opts = cc.combotree('options');
var values = cc.combotree('getValues');
var orderedValues = opts.orderedValues || [];
var node = cc.combotree('tree').tree('find', id);
if (node.checked){
orderedValues.push(String(node.id));
} else {
var index = $.inArray(String(node.id), orderedValues);
if (index >= 0){
orderedValues.splice(index, 1);
}
}
values.sort(function(a,b){
var i1 = $.inArray(a, orderedValues);
var i2 = $.inArray(b, orderedValues);
return i1<i2 ? -1 : 1;
});
opts.orderedValues = values;
cc.combotree('setValues', values);
}
Logged
joker
Newbie
*
Posts: 17


View Profile Email
« Reply #2 on: November 08, 2015, 11:03:42 PM »

Thanks for your reply,but after I add these codes, the combotree don't run well.When user check it,it become slowly,and user can't choose the second node.In firebug,console shows "too much recursion".
Logged
jarry
Administrator
Hero Member
*****
Posts: 2298


View Profile Email
« Reply #3 on: November 08, 2015, 11:45:44 PM »

Please refer to http://jsfiddle.net/bh9v02tt/
Logged
joker
Newbie
*
Posts: 17


View Profile Email
« Reply #4 on: November 09, 2015, 01:30:13 AM »

It is very strange.your code runs very well in jsfiddle,but in my demo page,it still have problem.

Code:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Multiple ComboTree - jQuery EasyUI Demo</title>
<link rel="stylesheet" type="text/css" href="../../themes/default/easyui.css">
<script type="text/javascript" src="../../jquery.min.js"></script>
<script type="text/javascript" src="../../jquery.easyui.min.js"></script>
</head>
<body>
<input id="cc" style="width:400px"></input>
</body>
<script>
var data = [{
"id":1,
"text":"My Documents",
"children":[{
"id":11,
"text":"Photos",
"state":"closed",
"children":[{
"id":111,
"text":"Friend"
},{
"id":112,
"text":"Wife"
},{
"id":113,
"text":"Company"
}]
},{
"id":12,
"text":"Program Files",
"children":[{
"id":121,
"text":"Intel"
},{
"id":122,
"text":"Java",
"attributes":{
"p1":"Custom Attribute1",
"p2":"Custom Attribute2"
}
},{
"id":123,
"text":"Microsoft Office"
},{
"id":124,
"text":"Games"
}]
},{
"id":13,
"text":"index.html"
},{
"id":14,
"text":"about.html"
},{
"id":15,
"text":"welcome.html"
}]
}]

$('#cc').combotree({
    data: data,
multiple: true,
cascadeCheck: false,
onClick: function(node){
clickNode($('#cc'), node.id);
},
onCheck: function(node, checked){
clickNode($('#cc'), node.id);
}
});
function clickNode(cc, id){
var opts = cc.combotree('options');
var values = cc.combotree('getValues');
var orderedValues = opts.orderedValues || [];
var node = cc.combotree('tree').tree('find', id);
if (node.checked){
orderedValues.push(String(node.id));
} else {
var index = $.inArray(String(node.id), orderedValues);
if (index >= 0){
orderedValues.splice(index, 1);
}
}
values.sort(function(a,b){
var i1 = $.inArray(a, orderedValues);
var i2 = $.inArray(b, orderedValues);
return i1<i2 ? -1 : 1;
});
opts.orderedValues = values;
cc.combotree('setValues', values);
}
</script>
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!