
[英]Js promise for calculator
我有一個簡單的計算器 function,是我為編碼挑戰而編寫的。 現在我遇到了額外calculate function 的問題,它應該返回 promise。 以下是 promise 需要滿足的測試: 以上calculate function 我寫的只通過了第一個測試,其他都沒有。 我擔心我做錯了。 ...
[英]Js promise for calculator
我有一個簡單的計算器 function,是我為編碼挑戰而編寫的。 現在我遇到了額外calculate function 的問題,它應該返回 promise。 以下是 promise 需要滿足的測試: 以上calculate function 我寫的只通過了第一個測試,其他都沒有。 我擔心我做錯了。 ...
[英]How to delay further UI requests until current promise is resolved
在 web 頁面中,我有一個由服務器 promise 計算的輸入。 現在,如果用戶在結果完成之前開始輸入,他的所有文本將被 promise 結果替換。 我需要保持或阻止按鍵事件,就像同步方法一樣,因此,即使用戶在 promise 結果之前開始鍵入,按鍵事件也會在 promise 解析之后執行。 目 ...
[英]Resolve is returned before for loop is completed inside a Promise
我很困惑為什么return resolve({ status: true, data: newIDs }); 在for循環完成之前被調用。 代碼 期待我希望 for 循環獲取所有新插入的 id,並將它們存儲到newIDs數組中。 完成后,我可以返回包含數據的解決方案。 然而,這部分我不太明白的是 ...
[英]Javascript uncaugh error in promise even with a catch
使用 Javascript,我試圖在提交表單時調用外部 API。 我正在使用 promises 以便在調用完成后設置后續操作並捕獲最終錯誤。 這就是我的問題所在,即使我認為我正確地捕獲了我的錯誤,控制台也會拋出一個未捕獲(承諾)錯誤:[我拋出的錯誤] 我不懂為什么。 這是我的代碼的最小版本,它會在 ...
[英]Promises and Async/Await don't seem to do anything in Express/node
我正在學習節點和表達,我正在嘗試實現一個 function,它從用戶上傳的 csv 文件中檢索數據。 數據應該先處理然后輸出到控制台,但它在處理之前輸出一個空數組。 我按照我在網上找到的教程中的異步/等待示例進行操作,但問題仍然存在,我不確定如何繼續。 輸出: ...
[英]Difference between callback and promise when using `net.connect`
我已經構建了一個簡單的腳本來檢測端口是否在我的機器上打開/關閉。 我已經成功地使用老式回調方式使其工作,但無法使其與 Promise(異步/等待)一起工作。 任何線索為什么下面的兩個腳本不完全相同? 使用回調,它工作得很好。 使用 Promise (async/await) 它通過拋出“uncaug ...
[英]TypeError: Cannot read properties of undefined in the conversion app how to resolve it
運行以下語句后,它會在控制台選項卡中顯示以下錯誤在控制台中運行的命令convert(100, 'CAD', 'USD') 運行上述轉換聲明請求后控制台顯示錯誤 `暫停 promise 拒絕類型錯誤:無法讀取未定義的屬性在此處的代碼 64 行 const rate = ratesByBase[fro ...
[英]Is there a way to run this http response callback in an asynchronous way?
我正在構建一個基本的 http 服務器(僅在 lan 內部使用,做一些事情)並為此使用 node.js。我已經啟動了我的服務器並編寫了一個基本回調 function 來響應 http 請求。 但是,我想看看如果我正在運行的 function 需要一些時間來結束(例如數據庫查詢)會發生什么。 所以我 ...
[英]Problem with recursive Promises - Node.js and cheerio webscraping recursively fetching site categories
我正在嘗試使用遞歸承諾來獲取已抓取網站類別內的所有子類別。 看起來我的代碼應該可以正常工作,但只有當我使用“拒絕”而不是解析時它才有效。 有些東西阻止了 promise 的蜂鳴,但我無法找到問題的原因。 這是我嘗試實現的 promise。 我很感激任何幫助。 它應該以這種方式工作,首先它為該類別獲取 ...
[英]filtering a promise iterated result array into a new array vue js
如何將舊數組的值插入到新的 arr promise 中。 由於 vue 的反應性,需要一種拼接方法。 不知何故 newArray 是空的,沒有得到任何值。 https://codesandbox.io/s/sweet-sammet-fyomv0?file=/src/components/Exam ...
[英]Struggling with Promise.race() implementation
我看到了以下 Promise.race() 的實現。 我發現很難理解它是如何工作的。 第一部分:以下說法正確嗎? Promise.resolve(innerPromise) 將始終以 innerPromise 為值返回已解決的 promise 並且因為它總是解決,所以我將始終以 in.then 塊 ...
[英]Javascript: return promise after promise chaining
JavaScript 新手問題:我希望能夠編寫一個參與 promise 鏈的 function,同時在其中進行一些 promise 鏈接。 在鏈結果中的最后一個 promise 之后,我想返回 promise 以便 function 之外的鏈可以繼續。 這是我的示例代碼。 有趣的部分是第 10 ...
[英]Iterating through an array with a fakeAPI promise function Vue.js
<template> <div class="hello"> <h1>Example 2</h1> <input @click="send" type="button" value="Send" /> <div class="out ...
[英]Promise allSettled running before promise finally
我有一個 function 嘗試加載 web 圖像並跟蹤加載圖像的計數和失敗圖像的計數。 我正在使用fetch加載圖像,並在驗證所有圖像后使用Promise.allSettled運行操作。 我面臨的問題是 finally 塊。 對於最后一張圖片,finally 塊在allSettled回調之后運行 ...
[英]Will the results of a request to the same API be overwritten?
我有兩個觸發請求的按鈕,都是對同一個API的數據請求,不同的按鈕代表不同的參數。 例如,按鈕 A 請求 2023 年的數據,按鈕 B 請求 2022 年的數據:// Click button A fetch('same/api', { body: { year: 2023 } }) ...
[英]Returning value to a map within a promise from another promise
我正在做一個項目,並且在 Node.js 的較新方面。 這是其他人的原始實現,我對 promises 有疑問,我知道它很可能與 async/await 或 promise.all 有關,但我已經花了很多時間嘗試但仍然沒有得到想要的結果。 我要去 PlaceStore 並返回 promise 以從 ...
[英]Does promise need call stack to be empty to get resolved
我使用process.binding('util').getPromiseDetails如下所示獲取 promise 狀態,我使用節點dns返回 promise 的模塊函數。然后我查詢 promise 是否以同步方式解析,但結果始終顯示 promise 未解析即使答案通常以毫秒為單位。 我的問題是我 ...
[英]i have a custom structural directive that using a promise in the ngOnInit to get an auth state from an API that doesn't refresh when i login or logout
我有一個自定義結構指令,它在 ngOnInit 中使用 promise 從 API 獲取 auth state,該指令顯示或刪除基於它從 API 獲取的 auth state 的元素, 它工作正常但是當我登錄時指令仍然在舊的 state 上並且你應該刷新頁面以便指令更新,在指令的 ngDocheck ...
[英]Uncaught (in promise) TypeError: this.fetchTasks is not a function
我正在使用 Vue.js,這是我的代碼。 fetchTasks() 是一個異步 function 所以我看不出問題出在哪里。 我的數據在 http://localhost:3000/tasks 的 json 服務器上這是代碼: 我嘗試使用 await 調用它,但出現錯誤 Uncaught (in ...
[英]Turning a promise in a for loop into an array of values
我有以下代碼: 我正在嘗試遍歷數組combinedIds (其中包含許多 mongoDB id)並基於它通過從后端獲取其他 id 創建一個新數組newIds 。 我正在使用遞歸異步 function,一切正常,但是由於 function 返回 promise,我不確定如何將它轉換為簡單的值數組,因為 ...