在 JavaScript 中的条件运算符内执行多个语句
Execute multiple statements inside conditional operator in JavaScript
我想呈现 2 个数组,第一个数组呈现在第二个数组之上,在条件运算符内并且不想连接具有重复元素的数组。
someCondition ? (
arr1.map(elm => renderItem(elm)),
arr2.map(elm => renderItem(elm))
) : null
但是,这只会呈现第二个数组而忽略第一个数组。
此外,不想连接两个数组然后从连接的数组中过滤元素,因为第二个数组有时可能非常大。
您可以在此处使用 React Fragments:
someCondition ? (
<>
{arr1.map(elm => renderItem(elm))}
{arr2.map(elm => renderItem(elm))}
</>
) : null
我想呈现 2 个数组,第一个数组呈现在第二个数组之上,在条件运算符内并且不想连接具有重复元素的数组。
someCondition ? (
arr1.map(elm => renderItem(elm)),
arr2.map(elm => renderItem(elm))
) : null
但是,这只会呈现第二个数组而忽略第一个数组。
此外,不想连接两个数组然后从连接的数组中过滤元素,因为第二个数组有时可能非常大。
您可以在此处使用 React Fragments:
someCondition ? (
<>
{arr1.map(elm => renderItem(elm))}
{arr2.map(elm => renderItem(elm))}
</>
) : null