JQuery EasyUi Tree : the onCheck fires after the onload : need only after user checking

StackOverflow https://stackoverflow.com/questions/19327842

  •  30-06-2022
  •  | 
  •  

Question

When using JQuery EasyUi Tree, i load an array with checked nodes. My pb is that my onCheck function is fired after the onload of the data, and i would like to fire that onCheck method only when i click the checkbox

The documentation says : "Fires when users click the checkbox." cf : http://www.jeasyui.com/documentation/tree.php

I don't know what is wrong in my code. If you have an idea on how to do that, it will be nice :)

Here is my code:

<script type="text/javascript">

        //Enable Drag and drop
        $(function(){
            $('#tt').tree({
                dnd: true,
                url: 'get_activite_data.php',
                cascadeCheck: true,

                onLoadSuccess: function(node,data){
                    $('#tt').tree('expandAll')
                },

                onDrop: function(targetNode, source, point){  
                    var targetNode = $('#tt').tree('getNode', targetNode); 

                    .......
                }
                ,


                onCheck: function(node,checked){  
                    $.messager.confirm('Confirm','I want to be fire only when user click manually the checkbox', function(r){...});  

                }               

            });
        });
Was it helpful?

Solution 2

Thanks a lot Novice Rambo :)

I did some changes to make it works:

<script type="text/javascript">
    isLoadingTime = true;

    //Enable Drag and drop
    $(function(){
        $('#tt').tree({
            dnd: true,
            url: 'get_activite_data.php',
            cascadeCheck: true,

            onLoadSuccess: function(node,data){
                $('#tt').tree('expandAll');
                isLoadingTime = false;
            },

            onCheck: function(node,checked){  
                if (isLoadingTime) {
                    return;
                }else{
                    //here the function to update db when user click manually
                }
            }
        });


    });
</script>

OTHER TIPS

try this...

var isLoadingTime = true;

....

if (isLoadingTime) {
    return;
}

....

isLoadingTime = false;

I edited your code:

<script type="text/javascript">
var isLoadingTime = true;

//Enable Drag and drop
$(function(){
    $('#tt').tree({
        dnd: true,
        url: 'get_activite_data.php',
        cascadeCheck: true,

        onLoadSuccess: function(node,data){
            $('#tt').tree('expandAll')
        },
        onDrop: function(targetNode, source, point){  
            var targetNode = $('#tt').tree('getNode', targetNode); 

            .......
        },
        onCheck: function(node,checked){  
            if (isLoadingTime) {
                return;
            }

            $.messager.confirm('Confirm','I want ... checkbox', function(r){...});  
        }
    });

    isLoadingTime = false;
});
</script>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top