有没有一种方法,使在反应原生一个阵图的结果内的onpress导航?

问题描述 投票:1回答:1

我在this.state.members名称的简单阵列。我使用的地图功能迭代的成员。我想添加一个按钮,每一个成员的话,当我点击他们,我去一个专门为每个成员的屏幕。我测试outise循环按钮,它工作。但是,对于那些地图功能里面,它说:“不确定是不是(评估‘_this2.props.navigation’函数)onPress对象”我花了一整天试图了解正在发生的事情没有任何的运气。任何帮助将不胜感激。这里是我的代码

import { StyleSheet, Text, View } from "react-native";
import { ListItem, Button } from "react-native-elements";

export default class ProfileScreen extends React.Component {
 static navigationOptions = {
   header: null
 };

 constructor(props) {
   super(props);
   this.state = {
     members: ["Allie", "Gator", "Lizzie"],
     id_groupe: "",
     groupe: ""
   };

   // this.handleSubmit = this.handleSubmit.bind(this);
 }
 render() {
   const members = this.state.members;
   const namesList = members.map(function(name, i) {
     return (
       <Button
         onPress={() => this.props.navigation.navigate("Home")}

         title={name}
         key={i}
       />
     );
   });

   return (
     <View style={styles.container}>
       <View>{namesList}</View>
       <View>
         <Button
           title="Back to home"
           onPress={() => this.props.navigation.navigate("Home")}
         />
       </View>
     </View>
   );
 }
}

const styles = StyleSheet.create({
 container: {
   flex: 1,
   backgroundColor: "#fff",
   alignItems: "center",
   justifyContent: "center"
 }
});
react-native react-navigation
1个回答
4
投票

只需使用一个箭头的功能,你不会有this问题。但是,不知道你的实际问题,如果箭头功能的工作原理让我们来看看,如果您有任何其他问题。 Arrow功能,当你与地图迭代:

const namesList = members.map((name, i) => {
     return (
       <Button
         onPress={() => this.props.navigation.navigate("Home")}
         title={name}
         key={i}
       />
     );
   });
© www.soinside.com 2019 - 2024. All rights reserved.