react-native - 在 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}
/>
解决方案
推荐阅读
- git - 具有多个分支的 Jenkinspipline Git SCM 结帐
- python - 如何将变量添加到python中的集合中的每个项目
- python - 如何从 pytorch 输出张量中提取具有置信度得分的关键点?
- java - 从 arraylist 中删除自定义对象并返回干净的 arrayList
- jenkins - Gerrit 触发器插件未在 Jenkins 中列出
- javascript - 使用 jquery 验证器进行验证时出现下拉设计问题
- wpf - C# WPF Datagrid 在 xaml 中绑定到字符串数组
- linux - 找不到 ffmpeg 命令,但 pip 列表显示 ffmpeg
- java - 在静态方法中同步 - 这是类级别的锁吗?
- php - PHP作曲家耗尽内存......为什么?怎么了?