我在這里有這個條件來檢查值是否未定義
console.log("Value: " typeof getValues('departmentId'))
if (String(getValues('departmentId')) != "" ||
String(getValues('departmentDesc')) != "" ||
typeof getValues('departmentId') !== undefined ||
typeof getValues('departmentDesc') !== undefined){
dispatch(setIsConfirm(true))
console.log("Clearing fields || Value: " getValues('departmentId'))
}
但由于某種原因,即使它未定義它仍然運行,這是 控制臺的圖片
uj5u.com熱心網友回復:
typeof回傳一個字串。所以你需要這樣做:
console.log("Value: " typeof getValues('departmentId'))
if (typeof getValues('departmentId') !== "undefined" || typeof getValues('departmentDesc') !== 'undefined'){
dispatch(setIsConfirm(true))
console.log("Clearing fields || Value: " getValues('departmentId'))
}
另外,請確保您確實需要 OR||運算子而不是 AND &&。如果需要,更換它。
uj5u.com熱心網友回復:
我和這個一起去了:
if ((String(getValues('departmentId')) !== "" && typeof getValues('departmentId') !== "undefined") ||
(String(getValues('departmentDesc')) !== "" && typeof getValues('departmentDesc') !== "undefined")){
dispatch(setIsConfirm(true))
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/490535.html
標籤:javascript 反应
上一篇:獲取帶有url的隱藏文本欄位以在懸停jQuery上更新影像
下一篇:分析Marklogic搜索請求
