繁体   English   中英

如何在 ReactJS 中执行多个 map 条件?

[英]How to do Multiple map condition in ReactJS?

我正在使用 reactjs javascript。 我想要两个 map 条件执行单个操作。

我有一个像这样的 map: {fname.map(fileName => (<label>{fileName}</label>}}

另一个是:

{fname.document.map(fileName => (<label>{fileName.documentName.map(sff=>sff)}</label>))}

fname是一个数组:

const [fname, setfname] = useState([]);

我已经在使用 fname 条件:

{fname ? 
<>
//something already goes here
</>
:
<>
//Here is only one condition is working. I want to make it work one map at a time. If one fails other should work.
</>
}

基本上我想要的是:如果一个条件 map 失败,那么另一个应该工作。 他们两个都在工作,但我想让它一次只工作一个,或者两个。

我怎样才能做到这一点?

也许这不是最好的解决方案,但你可以使用嵌套条件。

喜欢

{fname ? 
    <>
    //something already goes here
    </>
    :
    <>

    //Here is only one condition is working. I want to make it work one map at a time. If one fails other should work.

       //New condition
    otherCondition ? <></> : <> </>
    </>
    }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM