我没有得到数据库查询的结果,而是得到了'undefined'
有人可以告诉我这里缺少什么吗?
DbManager.js
getCameras() {
db.transaction(tx => {
tx.executeSql('select * from cameras;', [],
(_, result) => { return result.rows._array });
});
}
App.Js
async componentDidMount() {
dbManager.createDatabase();
//dbManager.insertCamera('Canon Canonet QL 17');
let data = await dbManager.getCameras();
console.log(data);
}
答案 0 :(得分:1)
您需要返回一个Promise
和resolve
及其结果。
getCameras() {
return new Promise((resolve, reject) => {
db.transaction(tx => {
tx.executeSql('select * from cameras;', [], (_, result) => {
resolve(result.rows._array)
});
});
})
}
async componentDidMount() {
dbManager.createDatabase();
//dbManager.insertCamera('Canon Canonet QL 17');
let data = await dbManager.getCameras();
console.log(data);
}