【发布时间】:2018-02-13 11:30:05
【问题描述】:
我现在正在使用 React Native 开发一个 APP,我想从 FlatList 的每个项目中进行导航。
例如,使用create-react-native-app。在 App.js 中,代码如下:
export default class App extends React.Component {
render() {
return (
<View style={styles.container}>
<Text>Open up App.js to start working on your app!</Text>
<Text>Changes you make will automatically reload.</Text>
<Text>Shake your phone to open the developer menu.</Text>
<FlatList
data={[{key: 'a'}, {key: 'b'}]}
renderItem={({item}) => <Text>{item.key}</Text>}
/>
</View>
);
}
}
当我单击 FlatList 的一个项目时,我想导航到另一个组件,我的代码如下:
export default class App extends React.Component {
cb() {
this.props.navigator.push({
component: QuestionDetail
});
}
render() {
return (
<View style={styles.container}>
<Text>Open up App.js to start working on your app!</Text>
<Text>Changes you make will automatically reload.</Text>
<Text>Shake your phone to open the developer menu.</Text>
<FlatList
data={[{key: 'a'}, {key: 'b'}]}
renderItem={({item}) => <Text onPress={this.cb.bind(this)}>{item.key}</Text>}
/>
</View>
);
}
}
但是有一个错误。
任何人都可以从 FlatList 的项目中制作导航器吗?事实上,FlatList 的每一项在被点击时都应该成为一个导航器。
谢谢!
【问题讨论】:
-
你在使用 react-navigation 吗?
-
不,我不知道怎么用。其实我是想用FlatList渲染一个列表,当点击每个item时,页面会跳转到另一个组件
标签: javascript reactjs react-native