我面临困难返回包含嵌套映射数组的渲染
renderData(data) {
return (
<View>
{
data.map((myData, index1) => {
return (
<Text key={'ev' + index1}>{myData.name}</Text>
myData.children.map((children, index2) => {
return (
<Text key={'pi' + index2}>{children.id}</Text>
)
})
)
})
}
</View>
)
}
这是我的语法错误。正确的方法是什么?
我还试图将第二个功能放在括号中:
renderData(data) {
return (
<View>
{
data.map((myData, index1) => {
return (
<Text key={'ev' + index1}>{myData.name}</Text>
{
myData.children.map((children, index2) => {
return (
<Text key={'pi' + index2}>{children.id}</Text>
)
})
}
})
}
</View>
)
}
用卷曲brakcets包装第二映射功能
const renderData = data => {
return (
<View>
{data.map((myData, index1) => {
return (
<>
<Text key={"ev" + index1}>{myData.name}</Text>
{myData.children.map((children, index2) => {
return <Text key={"pi" + index2}>{children.id}</Text>;
})}
</>
);
})}
</View>
);
};