EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: jokersoft on December 22, 2013, 01:47:15 PM



Title: tree onCheck fires for every checked node after load
Post by: jokersoft on December 22, 2013, 01:47:15 PM
I have a dynamically loading tree.
In this tree config I have onCheck that fires some script.
Problem is onCheck fires for every node with attr "checked" after load.

1) Question is can the nodes be somehow loaded checked or unchecked without triggering onCheck?
2) Also, what can I send via JSON so the node become "indeterminate"? Or the only way is to use filter?


Title: Re: tree onCheck fires for every checked node after load
Post by: stworthy on December 22, 2013, 05:39:45 PM
To prevent from triggering onCheck event when loading data, change onCheck event to an empty function and then restore it after load successfully.
Code:
var t = $('#tt');  // the tree object
var opts = t.tree('options');
var onCheck = opts.onCheck;
opts.onCheck = function(){};
t.tree('loadData',...);  // load data with no 'onCheck' event triggered
opts.onCheck = onCheck;  // restore the 'onCheck' event handler

If you are loading data from 'url', the better way is to customize the loader function.
Code:
$('#tt').tree({
  loader: function(param, success, error){
var opts = $(this).tree('options');
if (!opts.url) return false;
var onCheck = opts.onCheck;
opts.onCheck = function(){};
$.ajax({
type: opts.method,
url: opts.url,
data: param,
dataType: 'json',
success: function(data){
success(data);
opts.onCheck = onCheck;
},
error: function(){
error.apply(this, arguments);
opts.onCheck = onCheck;
}
});
  }
});


Title: Re: tree onCheck fires for every checked node after load
Post by: jokersoft on December 23, 2013, 02:43:03 AM
Tricky! Works, thanx!  :)
I also tried a more "flat" solution:
Code:
var editing = false;
...
onLoadSuccess: function(node, data){
editing = true;
},
onBeforeLoad: function(node, data){
editing = false;
},
onCheck: function(node, checked) {
if (editing) //do stuff
},

but it didn't work for some reason...