首页 > 解决方案 > 在 React Native 中按下时从按钮列表中获取键

问题描述

我正在显示Material Kit 按钮的列表(使用SectionList),并希望能够在单击它们时显示它们的键(即它们的索引) - 但是我正在努力让它与 MK 按钮一起工作。

任何帮助将非常感激。万分感谢!

带有 onPress 的按钮生成器:

AllConnectionsItemButton = MKButton.flatButton()
  .withOnPress( (key) => alert(key))
  .build()

部分列表:

<SectionList
  renderItem={({item, index, section}) => (
  <AllConnectionsItemButton key={index}>
    <Text>{item.name}</Text>
  </AllConnectionsItemButton>
    )}
  renderSectionHeader={({section: {title}}) => (
    <View>
      <Text>{title}</Text>
    </View>
  )}
  sections={this.state.myList}
  keyExtractor={(item, index) => item + index}
/>

标签: react-nativereact-native-flatlistreact-native-sectionlist

解决方案


推荐阅读