【发布时间】:2021-08-11 08:30:21
【问题描述】:
我一直在尝试将 var 分配给 result 却没有运气
self.addProductToCart = function (data, event) {
var theproduct = db.pos_products.get({id: data.idProduct}).then(function (pos_product) {
// console.log(pos_product.value); // returning results, which indicates it is working
return pos_product.value
}).catch(function(error) {
console.log ("Ooops: " + error);
});
console.log (theproduct); // retunrning no results only DexiePromise { listeners: Arrar(0), _lib.....
}
我也试过
async function myfunction(idProduct) {
let result = await db.pos_products.get({id: idProduct}).then(function (pos_product) {
return pos_product.value
}).catch(function(error) {
console.log ("Ooops: " + error);
});
}
self.addProductToCart = function (data, event) {
var theproduct = myfunction(data.idProduct);
console.log ('theproduct');
console.log (theproduct); // retunrning Promise {<pending>}
}
我希望有人可以提供帮助。我需要变量 theproduct 稍后在 current 中使用
【问题讨论】:
标签: javascript dexie