我的 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.name
和 data.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/