我想在查询外部使用for循环,但它打印为空。
sql = 'SELECT * FROM people';
let currMarker = [];
db.all(sql, [], (err,rows) => {
if (err) return console.error(err.message);
currMarker = rows;
for (let i = 0; i < currMarker.length; i++) {
console.log(currMarker[i].name);
console.log(currMarker[i].username);
}
});
我想像这样使用它:
sql = 'SELECT * FROM people';
let currMarker = [];
db.all(sql, [], (err,rows) => {
if (err) return console.error(err.message);
currMarker = rows;
});
for (let i = 0; i < currMarker.length; i++) {
console.log(currMarker[i].name);
console.log(currMarker[i].username);
}
1条答案
按热度按时间2izufjch1#
这里有一个解决方案。