What's wrong with this callback function?

1. When data.length=3, only 2 pieces of data are stored in the database, is it because the callback function is written wrong?

function insertData (data) {

    var events = [];
    var count = 0;
    for (var i = 0; i < data.length; iPP) {
        (function(i){
            var obj = data[i];    
            function insert(callback){
                countPP;    
                console.log(count);
                _getNewSN({
                    query : {category : "ProjectOID_" + obj.ProjectOID},
                    success : function(sn){
                        var param = [
                                parseInt(obj.FunctionCode) ,
                                parseInt(obj.StartRegister) ,  
                                parseInt(obj.Length) , 
                                obj.Description, 
                                obj.ProjectHardwareOID , 
                                sn.SN];
                        var sql = "insert into " + 
                                "plcModbusTCPDB(FunctionCode,StartRegister," + 
                                "Length,Description,ProjectHardwareOID," + 
                                "DataID) values(?,?,?,?,?,?)";
                        yjDBService.exec({
                            sql:sql,
                            parameters : param,
                            success : sender.success,
                            error : sender.error
                        });
                        callback(null,obj);
                    },
                    error : sender.error
                })
            }  
            events.push(insert);
        })(i)
    }

    async.waterfall(events,function(err,result){
        if(err){
            sender.error(err);
        }else{
            sender.success(result);
        }
    })    
}-sharp-sharp-sharp 

the environmental background of the problems and what methods you have tried

related codes

/ / Please paste the code text below (do not replace the code with pictures)

what result do you expect? What is the error message actually seen?

Apr.08,2022

may not be able to execute into the success method once.
Why doesn't the error of the _ getNewSN method call callback


you put the code "countPP" in the success function

Menu