如何在嵌套地图函数中应用条件?

How to apply conditionals in a nested map function?

我想处理我的 item.fieldtype 结果的每个字符串,但我没有找到方法,有人知道吗?

....
      <SafeAreaView style={{flex: 1}}>
          <View>
            {Object.keys(Body).length > 0 ? (
              Body.map(item => <Text key={uuid.v4()}>{item.field}</Text>
              // if (item.fieldtype == "Numeric") <Text>Numeric</text> ===> apply here
              //else if (item.fieldtype == "Text" ) <Text>Text</text> ===> "" ""      
              )
            ) : (
              <Text>Testado</Text>
            )}
          </View>
        </SafeAreaView>
...

您可以在地图中使用片段标签(或只是 View)和 return 多个项目:

<SafeAreaView style={{flex: 1}}>
  <View>
    {Object.keys(Body).length > 0 ? 
      (Body.map(item => 
       <React.Fragment key={uuid.v4()}>
          <Text>{item.field}</Text>
          {item.fieldtype == "Numeric" ? <Text>Numeric</Text> : null}
          {item.fieldtype == "Text" ? <Text>Text</Text> : null}
       </React.Fragment>))
      : (<Text>Testado</Text>)}
  </View>
</SafeAreaView>

(请注意,如果您有可用的稳定 ID 而不是为每个渲染上的每个项目生成新的 uuid,那将是理想的)