找出按下哪个组件

时间:2017-07-24 08:19:45

标签: react-native

我如何知道已按下哪个活动详情?

renderPeople() {
        if (this.state.teachers != null && this.state.teachers.length >= 1) {
          return this.state.teachers.map(teacher => (
            <ActivityDetail key={teacher.UID} person={teacher} onPress={() => this.setState({ isTeacherVisible: true })} />
          ));
        }
        return null;
      }

1 个答案:

答案 0 :(得分:0)

您也可以将UID保存到道具

this.setState({ isTeacherVisible: true, selectedTeacher: teacher.UID })

完整代码:

renderPeople() {
    if (this.state.teachers != null && this.state.teachers.length >= 1) {
        return this.state.teachers.map(teacher => (
        <ActivityDetail key={teacher.UID} person={teacher} onPress={() => this.setState({ isTeacherVisible: true, selectedTeacher: teacher.UID })} />
        ));
    }
    return null;
}