EasyUI Forum
May 08, 2024, 01:19:13 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: tree onCheck fires for every checked node after load  (Read 8400 times)
jokersoft
Newbie
*
Posts: 14


View Profile
« 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?
Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #1 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;
}
});
  }
});
« Last Edit: December 22, 2013, 05:41:26 PM by stworthy » Logged
jokersoft
Newbie
*
Posts: 14


View Profile
« Reply #2 on: December 23, 2013, 02:43:03 AM »

Tricky! Works, thanx!  Smiley
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...
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!