【发布时间】:2018-06-29 16:09:05
【问题描述】:
如何遍历我的数据结构并创建 React 组件?
{
component: "View",
attributes: {
id: 'main'
},
child: [
{
component: "Text",
content: "Hello World!"
},
{
component: "Link",
attributes: {
href: "#"
},
child: [
{
component: "Text",
content: "Click me!"
}
]
}
]
}
会输出:
<View>
<Text>Hello World!</Text>
<Link>Click me!</Link>
</View>
无论嵌套组件的数量如何,我如何才能动态地实现这一点?
我能够制作顶级组件,但遍历 child 元素是我碰壁的地方。
【问题讨论】:
-
你尝试了什么,你有代码给我们看吗?
标签: json reactjs react-native traversal