this.getDetails();
getDetails = () => {
let userDetails = [];
db.transaction((tx) => {
tx.executeSql('select * from users where role=?',['students'],(tx,results) => {
let details = []
if(results.rows.length > 0){
for(let i=0; i < results.rows.length; i++){
details.push(results.rows.item(i));
}
}
userDetails = details;
//Data is displayed here
console.log(userDetails)
})
})
// Data is not printed here
console.log(userDetails) // []
}
在上面的代码片段中,我能够在 tx.executeSql 中获取数据(userDetails),但不能在 db.transaction 块之外获取。
谁能帮我解决如何在 db.transaction 块之外显示数据。