javascript - 在 React Native 中显示映射数组中的数组元素

标签 javascript reactjs

我的 reducer 是:

reducer :

const initialState = {
  1: {
     id: '1',
     name: 'Name1',
     number: 11,
     myArray:["P1tag1","P1tag2", "P1tag3"]
    },
  2: {
     id: '2',
     name: 'Name2',
     number: 22,
     myArray:["P2tag1","P2tag2", "P2tag3"]
    }
}

使用了mapStateToProps并映射了newData。我像这样渲染数据:

   const renData = Object.keys(this.props.newData).map((key, idx) => {
    let data = this.props.newData[key]
      return (
          <View>
            <Text>{data.name} </Text>

            <Text>{data.number} /Text>

            <Text>
              myArray // <= How do I show the items from myArray here? 
            </Text>
          </View>

      )
  })

data.namedata.number 显示正常。我正在尝试弄清楚如何显示 data 中的数组 myArray

谢谢。

最佳答案

简单地映射它们:

<View> //or any other wrapper here
   {data.myArray.map((item, index) => <Text key={index}>{item}</Text>)}
<View>

关于javascript - 在 React Native 中显示映射数组中的数组元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46115362/

相关文章:

javascript - Bootstrap + Zeroclipboard = 悬停时无法显示工具提示?

javascript - 查询对象数组javascript

reactjs - 如何在 Typescript 模块 (.tsx) 中导入在 JSX 中定义的现有 React 组件

javascript - 如何将图像从 Node.js 发送到 React.js?

javascript - Html 链接在后台调用 Php 函数

php - 发送 POST 数据时是否可以重定向?

reactjs - 在根项目中找不到任务 'bundleReleaseJsAndAssets'

javascript - ReactJS 组件什么时候应该进行 AJAX 调用来更新 props 的状态?

javascript - 将整数列表发送到 REST API 会抛出 415(不支持的媒体类型)

javascript - 在 JavaScript 中从 RGB 像素数组中将图像绘制到屏幕上的最快方法是什么?