簡體   English   中英

如何在三元運算符用於條件渲染的情況下對深度嵌套的值使用可選鏈接?

[英]How to use optional chaining for deeply nested values in react where ternary operator used for conditional rendering?

我有這個深深嵌套的價值

eventsubcategoryvalue: data.body.spending.requestspend==='y'? data.body.spending.allowspend: chargeamount

所以這里的eventsubcategoryvalue是根據三元運算符的結果來決定的。 我想在這里使用可選鏈接而不是擁有這個復雜的嵌套事物。 我該如何重新編寫它? 即使瀏覽了 MDN 文檔,我也無法理解。

如何用可選鏈接重寫它?

嘗試

(eventsubcategoryvalue) ? ( data.body.spending.requestspend === 'y' ? data.body.spending.allowspend : chargeamount ) : chargeamount 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM