如何在筛选所有'Finish'
结果后显示row.name
?
npmSql.query("SELECT name FROM sqlTable", function(err, rows, fields) {
rows.forEach(function(row) {
console.log(row.name);
});
}, function () { console.log('Finish'); });
我试图按照Node.js - Using the async lib - async.foreach with object这样的答案,但没有运气:(
更新
function abc() {
npmSql.query("SELECT name FROM sqlTable", function(err, rows, fields) {
rows.forEach(function(row) {
console.log(row.name);
});
}, function () { console.log('Finish'); });
}
答案 0 :(得分:4)
在console.log('Finish')
电话之后放置forEach
语句:
npmSql.query("SELECT name FROM sqlTable", function(err, rows, fields) {
rows.forEach(function(row) {
console.log(row.name);
});
console.log('Finish');
});
您正在使用标准的javascript Array.prototype.forEach
,这是同步的。您链接的问题涉及无关的异步foreach
函数。