扫码关注官方订阅号
rows.forEach(function(row, index) { row.count = getCount(); });
由于getCount是异步执行的,导致rows数组没有增加count这个键,那么我该怎么样让rows数组统一增加count这个键值。
欢迎选择我的课程,让我们一起见证您的进步~~
都是异步的了,当然用回掉函数或promise;
javascriptrows.forEach(function(row, index) { getCount(function(count){ rows.count = count; console.log(rows.count) }); }); function getCount(callback){ var count=1;//这里写1 只是举例 if(callback){ setTimeout(function(){ callback(count); },1000); } }
javascript
rows.forEach(function(row, index) { getCount(function(count){ rows.count = count; console.log(rows.count) }); }); function getCount(callback){ var count=1;//这里写1 只是举例 if(callback){ setTimeout(function(){ callback(count); },1000); } }
微信扫码关注PHP中文网服务号
QQ扫码加入技术交流群
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
PHP学习
技术支持
返回顶部
都是异步的了,当然用回掉函数或promise;