Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/392.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript JSX:映射中的条件语句_Javascript_Reactjs_Jsx - Fatal编程技术网

Javascript JSX:映射中的条件语句

Javascript JSX:映射中的条件语句,javascript,reactjs,jsx,Javascript,Reactjs,Jsx,我试图理解如何在JSX中合并条件语句。我有一个映射到选择框的对象数组。我想排除在indicator.name中包含子字符串“threshold”的项目 所以我不能使用三元运算符,因为没有“或”项。但是我不知道如何在这个映射中包含if语句。无论我做什么,我都会出错 setIndicator(e.currentTarget.value)} 已禁用={loading} > 挑选 {indicatorList.map(指示符=>( {indicator.label} ))} 我建议使用过滤方法过滤掉“

我试图理解如何在JSX中合并条件语句。我有一个映射到选择框的对象数组。我想排除在indicator.name中包含子字符串“threshold”的项目

所以我不能使用三元运算符,因为没有“或”项。但是我不知道如何在这个映射中包含if语句。无论我做什么,我都会出错

setIndicator(e.currentTarget.value)}
已禁用={loading}
>
挑选
{indicatorList.map(指示符=>(
{indicator.label}
))}

我建议使用过滤方法过滤掉“阈值”。这将返回您希望在JSX中包含的数组,您可以筛选该数组,然后映射:

<select
  defaultValue={defaultValue}
  onChange={e => setIndicator(e.currentTarget.value)}
  disabled={loading}
>
  <option key='' value=''>
    Select
  </option>
  {indicatorList.filter(indicator=>indicator.name.includes('threshold')).map(indicator => (
    <option key={indicator.name} value={indicator.name}>
      {indicator.label}
    </option>
  ))}
</select>
setIndicator(e.currentTarget.value)}
已禁用={loading}
>
挑选
{indicatorList.filter(indicator=>indicator.name.includes('threshold')).map(indicator=>(
{indicator.label}
))}
或返回空值:

<select
  defaultValue={defaultValue}
  onChange={e => setIndicator(e.currentTarget.value)}
  disabled={loading}
>
  <option key='' value=''>
    Select
  </option>
  {indicatorList.map(indicator => (
    indicator.name.includes('threshold')?<option key={indicator.name} value={indicator.name}>:nul
      {indicator.label}
    </option>
  ))}
</select>
setIndicator(e.currentTarget.value)}
已禁用={loading}
>
挑选
{indicatorList.map(指示符=>(
指示符.名称.包括('threshold')?:num
{indicator.label}
))}

indicatorList.filter(v=>v.includes(“阈值”)).map(…
谢谢!过滤然后映射是我所需要的