Javascript 如何从react native中的另一个类调用带有参数的函数?
我想在一个屏幕上显示侧面抽屉上列出的不同屏幕。我不想为每个屏幕创建相同的布局更改,因此当用户单击列表时,屏幕的中心部分将相应地更改,其他布局将保持不变 这是我的屏幕,其中内容随着状态中索引的变化而变化Javascript 如何从react native中的另一个类调用带有参数的函数?,javascript,reactjs,react-native,Javascript,Reactjs,React Native,我想在一个屏幕上显示侧面抽屉上列出的不同屏幕。我不想为每个屏幕创建相同的布局更改,因此当用户单击列表时,屏幕的中心部分将相应地更改,其他布局将保持不变 这是我的屏幕,其中内容随着状态中索引的变化而变化 class ScreenA extends Component { constructor(props) { super(props) this.state = { index: 0 }; // default screen index
class ScreenA extends Component {
constructor(props) {
super(props)
this.state = { index: 0 }; // default screen index
}
switchScreen(index) {
this.setState({ index: index })
}
render() {
let AppScreen = null;
if (this.state.index == 0) {
AppScreen = Screen1
} else if (this.state.index == 1) {
AppScreen = Screen2
} else if (this.state.index == 2) {
AppScreen = ScreenC }
return (
<Drawer ref={(ref) => { this.drawer = ref; }}
content={<Side_Drawer navigator={this.navigator} />}
onClose={() => this.closeDrawer()} >
<Container>
<Button
onPress={() => this.switchScreen(1)}/>
<AppScreen />
<Containert/>
</Drawer>
);
}
}
这是我的Side_抽屉,是ScreenA抽屉上的列表,我想从这里更改Screen A的switchScreen功能的索引,然后按下我想显示Screen C的列表
class Side_Drawer extends Component {
render() {
return (
<Container>
<Content>
<ListItem >
<Text onPress={()=>this.props.navigation.navigate('ScreenC')}>Goto Screen C</Text>
</ListItem>
</Content>
</Container>
);
}
}
module.exports = withNavigation(Side_Drawer);
我想要一个单屏幕应用程序,其中只有所需的屏幕部分会更改,否则将是相同的。传递要使用的参数
您可以将其转到侧菜单,因为您有屏幕数据要移动到AppScreen
内容={}
侧抽屉强文本
this.props.navigation.navigatethis.props.move}>
您可能希望为每个视图创建不同的组件重用所有视图中使用的组件并查看react本机导航:@TedNyberg我一直在为我的项目使用react导航,我想问题就出在这里。道具。导航。导航“ScreenC”,我想用一些代码来更改屏幕中的索引。AI也想更改切换屏幕功能中的索引,这样我就可以得到所需的屏幕。使用上述代码,我得到一个未定义索引的错误@hong developHave您检查了AppScreen的值了吗?