我正在使用 Cordova 應用程式嵌入 React 應用程式。在某個時間點,用戶連接到相機并在檢測到二維碼時出現通知。我希望代碼執行等到用戶輸入他/她的答案“是/否”,但我無法讓它作業。通知提示訊息按預期作業。
我需要它以某種方式暫停,例如async function( prompt例如)。我怎么能暫停代碼執行,直到用戶在螢屏上選擇是/否?我猜有一些async/await但看不到在哪里......到目前為止我嘗試過沒有成功:
let test = null;
let input2 = null;
notification = navigator.notification.prompt("Do you know this QR code?",
async function(input) {
input2 = input;
test = await NotificationFunction(input, Camera_content);
console.log(test)
console.log('input2')
return [test, input2]
});
let test2= await notification
console.log(test2)
console.log(notification)
console.log(await test)
提前非常感謝!
uj5u.com熱心網友回復:
也許你可以使用這樣的東西:
const promise = new Promise((resolve, reject) => {
navigator.notification.prompt(
'Do you know this QR code?',
async function (input) {
test = await NotificationFunction(input, Camera_content);
resolve([test, input]);
},
);
});
const [test, input] = await promise
也許這可以幫助https://javascript.info/promisify
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/439247.html
標籤:javascript 反应 科尔多瓦 迅速的
