Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/405.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/43.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何从函数中另一个函数的回调函数的返回值返回 exports.find\u last\u index=function(){ doc.useServiceAccountAuth(creds,function(err){ getCells博士( 1//表的索_Javascript_Node.js_Callback_Es6 Promise - Fatal编程技术网

Javascript 如何从函数中另一个函数的回调函数的返回值返回 exports.find\u last\u index=function(){ doc.useServiceAccountAuth(creds,function(err){ getCells博士( 1//表的索

Javascript 如何从函数中另一个函数的回调函数的返回值返回 exports.find\u last\u index=function(){ doc.useServiceAccountAuth(creds,function(err){ getCells博士( 1//表的索,javascript,node.js,callback,es6-promise,Javascript,Node.js,Callback,Es6 Promise,如何从函数中另一个函数的回调函数的返回值返回 exports.find\u last\u index=function(){ doc.useServiceAccountAuth(creds,function(err){ getCells博士( 1//表的索引 , { “最小行”:1 ,“最小列”:1 ,“最大行数”:1600 ,“最大列”:1 ,“返回空”:true } ,功能(错误,单元格){ var last; if(err)console.log(err); //控制台日志(单元格); 对

如何从函数中另一个函数的回调函数的返回值返回
exports.find\u last\u index=function(){
doc.useServiceAccountAuth(creds,function(err){
getCells博士(
1//表的索引
, {
“最小行”:1
,“最小列”:1
,“最大行数”:1600
,“最大列”:1
,“返回空”:true
}
,功能(错误,单元格){
var last;
if(err)console.log(err);
//控制台日志(单元格);
对于(var num=0;1600>num;num++){
if(单元格[num]。值==“”){
last=num-1;
打破
}
}
console.log(“-------------------------------”;
console.log(最后一个);
index=last;//index是全局变量
最后返回;
}
);
});

return index;//这可能不会直接帮助您,但可能会让您更好地了解回调的工作方式:
exports.find_last_index = function(){
    doc.useServiceAccountAuth(creds, function(err){ 
           doc.getCells(
               1    // index of sheet
             , {
                   "min-row" : 1    
                 , "min-col" : 1    
                 , "max-row" : 1600 
                 , "max-col" : 1  
                 , "return-empty" : true
             }
             , function(err, cells) {
                 var last;
                 if(err) console.log(err);
               //  console.log(cells);
                for(var num = 0; 1600 > num; num++) {
                      if(cells[num].value == ""){
                          last = num-1;
                          break;
                      }
                }
                console.log("-------------------");
                console.log(last);
                index = last; //index is global variable
                return last;
             }
         );
   });
   return index; //<--- It returns null
}