【问题标题】:React Native: Array of componentsReact Native:组件数组
【发布时间】:2020-05-04 01:07:58
【问题描述】:

我正在尝试打印一组 JSX 元素:

return (
        <View
        style={[
          commonStyles.sectionContainer,
          commonStyles.spaceBottom1x,
          { width: "100%" },
        ]}
      >
        { ['a', 'b'].forEach((letter) => { 

            <View>
                <Text>Hola</Text>
            </View>
        })}
        </View>
)

但它不打印...我错过了什么?

【问题讨论】:

    标签: javascript react-native jsx


    【解决方案1】:

    您可以使用 map 来代替。

    并使用带有包装{字母}的参数进行渲染。

    像这样:

    <View style={styles.app}>
      { ['a', 'b'].map((letter) => 
        <Text>{letter}</Text>
      )}
    </View>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-03-11
      • 2021-07-02
      • 2021-04-22
      • 2019-06-21
      • 1970-01-01
      • 2019-01-18
      相关资源
      最近更新 更多