【发布时间】:2019-03-13 09:03:53
【问题描述】:
我的代码在下面,根据 myArray.length 多次调用 doProcess,现在的问题是如何 我可以跟踪是否调用了多少次 doProcess ,我尝试使用计数器但似乎没有任何想法?不要担心doprocess被执行了,我已经做到了,我只想跟踪doprocess被调用了多少次。
doProcess(myArray, 0);
function doProcess(myArray, index) {
if (myArray.length === index) {
return;
}
data["users"] = array
data["random_code"] = myArray[index];
QuestionaireService.share_questionaire(me, data).then(function (response) {
if (response.status == "200") {
doProcess(myArray, ++index);
count++;
}
});
console.log("count", count)
}
【问题讨论】:
-
您的
count变量在哪里声明?我猜在功能之外?你目前得到的输出是什么? -
退出函数
-
多个计数,我只想最终计数不计数 1,计数 2 计数等等
-
你试图在
doProcess调用之后增加count,它永远不会增加,因为它是递归调用函数,在doProcess函数调用之前调用它 -
把这个
console.log("count", count)放到函数调用之外
标签: javascript angularjs function loops