【发布时间】:2019-07-31 10:16:17
【问题描述】:
在从 json 文件 (https://www.rallyssimo.it/wp-json/wp/v2/categories) 获取某些类别后,我需要在应用程序的抽屉中动态添加一些项目
json 示例(我需要该信息)
[
{
"id": 44,
.
.
"name": "ALTRI RALLY",
.
.
},
这是抽屉:
const CustomDrawerComponent = (props) => (
<SafeAreaView style={{flex:1}}>
<View style={{height:80, backgroundColor: 'white', alignItems: 'center', justifyContent: 'center'}}>
<Image
source={{uri: 'https://www.rallyssimo.it/wp-content/uploads/2016/08/rallyssimo-logo.png'}}
style={{ height: 60, width: 180}}
/>
</View>
<ScrollView>
<DrawerItems {...props} />
</ScrollView>
</SafeAreaView>
)
const AppNavigator = createDrawerNavigator(
{
Home: DashboardStackNavigator,
},
{
contentComponent: CustomDrawerComponent
}
);
const AppContainer = createAppContainer(AppNavigator);
//Main class
export default class App extends React.Component {
render() {
return <AppContainer />;
}
}
如何将项目(我将从 JSON 中获取)放入抽屉中?
【问题讨论】:
-
在每次获取时保持状态并更新状态。
标签: json react-native react-navigation react-navigation-drawer