How do I show the array which is nested in an array?
Code:
this.props.posts :
[
{"id":1, "name": "name01", "tags":["tag1, tag2, tag3, tag4"]},
{"id":2, "name": "name02", "tags":["tag2, tag4"]}
]
The way I'm trying to show is:
renData () {
const { posts, tags } = this.props.posts
return posts.map((key, idx) => {
return (
<View key = {idx}>
<Text style={{fontSize:18}}> // <= This works if tags not mapped
{ key.id } - { key.name }
</Text>
/*
tags.map((keyTag, idp) => { //<= This does not work.
<View key = {idp}> // <= idp not defined error.
<TouchableOpacity>
<Text> {keyTag} </Text> // <= How to show the content.
</TouchableOpacity>
</View>
});
*/
</View>
)
});
}
I want to show the content of the tags on each line.
UPDATE1:
renData () {
const { posts, tags } = this.props.tagPosts
return posts.map((post, postIndex) => {
return (
<View key = {postIndex}>
<View>
<Text style={{fontSize:18}}>
{ post.id } - { post.name }
</Text>
{
post.tags.map((tag, tagIndex) => {
<View key = {tagIndex}>
<TouchableOpacity>
<Text> {tag} </Text>
</TouchableOpacity>
</View>
})
}
</View>
)
});
}