React Native 动态添加屏幕

我想从可变数组动态添加屏幕。

这有效: 

http://img1.mukewang.com/62a15ed10001023011010650.jpg

但这不起作用: 

http://img3.mukewang.com/62a15edd0001f20a11900658.jpg

 它说:错误:找不到导航器的任何屏幕。您是否将任何屏幕定义为其子级?

我怎样才能修复第二个更“动态”?



动漫人物
浏览 134回答 2
2回答

MMMHUHU

您可以更改您components的对象列表。然后通过它们的键和值在项目内循环。const components = [&nbsp;{&nbsp; &nbsp;name: "Home",&nbsp; &nbsp;element: HomeScreen&nbsp;},&nbsp;{&nbsp; &nbsp;name: "Details",&nbsp; &nbsp;element: DetailsScreen&nbsp;}];const renderScreen = () => {&nbsp; let result = null;&nbsp; if (components) {&nbsp; &nbsp; result = components.map((item, i) => {&nbsp; &nbsp; &nbsp; &nbsp;return <Stack.Screen name={item.name} element={item.element} />&nbsp; &nbsp; });&nbsp; }&nbsp; return result;}return(&nbsp; {renderScreen()})

米琪卡哇伊

更改element => { <Stack... /> }为element => { return <Stack... /> }或&nbsp;element => ( <Stack... /> )
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript