首页 > 解决方案 > 为什么变量数据突然变成了item

问题描述

<View style={styles.container}>
  <SectionList
    sections={[
      { title: 'D', data: ['Devin'] },
      {
        title: 'J',
        data: ['Jackson', 'James', 'Jillian', 'Jimmy', 'Joel', 'John', 'Julie'],
      },
    ]}
    renderItem={({ item }) => <Text style={styles.item}>{item}</Text>}
    renderSectionHeader={({ section }) => (
      <Text style={styles.sectionHeader}>{section.title}</Text>
    )}
    keyExtractor={(item, index) => index}
  />
</View>;

你能告诉我为什么变量data突然变成item,我不知道这里发生了什么。

标签: androidreact-native

解决方案


您是否试图告诉为什么您的部分下的数据名称已更改为 renderItem 中的项目对?

SectionList 将作为for loop从中获取数据的地方工作

{[
  { title: 'D', data: ['Devin'] },
  { title: 'J', data: ['Jackson', 'James', 'Jillian', 'Jimmy', 'Joel', 'John', 'Julie'] }
]}

并作为项目一一返回。您也可以将项目更改为数据,它只是一个变量。

希望你得到答案。


推荐阅读