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
}