如何在ReactJS中实现多映射条件



我使用的是reactjs javascript。我想要将两个映射条件执行为一个操作。

我有一张这样的地图:{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.
</>
}

基本上我想要的是:如果一个条件映射失败,那么另一个应该工作。他们两个都在工作,但我想一次只工作一个,两个都可以。

我该怎么做?

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

{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 ? <></> : <> </>
</>
}

最新更新