0

我有一个数据源数组,其中包含多种类型的组,例如“我管理的组”、“我所属的组”和“最喜欢的组”。默认情况下,SectionList 在最后显示“收藏夹组”部分,但我想首先显示它。我该怎么做?请帮忙。

我的代码:

<SectionList
                renderItem={({ index, section }) =>
                  this._renderGroups(section.data[index], section.title, index)
                }
                stickySectionHeadersEnabled={true}
                renderSectionHeader={({ section: { title } }) => (
                  <View style={styles.headerTiltle}>
                    <Text
                      style={{
                        ...CommonStyles.Header1Style(20)
                      }}
                    >
                      {this.state.appString[title]}
                    </Text>
                  </View>
                )}
                sections={this.state.dataSource}
               // sections={[{ data: this.state.dataSource, index:2 }, { data: this.state.dataSource, index:0 }, {data: this.state.dataSource, index:1}]}
                // sections={[
                //   {title: "Favourite Groups", data: this.state.dataSource},
                //   {title: "Groups I Manage", data: this.state.dataSource},
                //   {title: "Groups I Belong To", data: this.state.dataSource}
                // ]}
                keyExtractor={(item, index) => item + index}
              />
4

1 回答 1

0

我必须更改将数据添加到最终数组的顺序。

var respArray = [];
if (favouriteGroups.length)
  favouriteGroups.map((item) => {
      item.s3photo = getSignedUrl( item.photo );
  });
  respArray.push({
    title: 'lbl_favourite_groups',
    data: favouriteGroups,
  });
if (managed_by.length)
  managed_by.map((item) => {
      item.s3photo = getSignedUrl( item.photo );
  });
  respArray.push({
    title: 'lbl_groups_i_manage',
    data: managed_by,
  });
if (belongs_to.length)
  belongs_to.map((item) => {
      item.s3photo = getSignedUrl( item.photo );
  });
  respArray.push({
    title: 'lbl_groups_i_belongs_to',
    data: belongs_to,
  });
于 2020-09-07T06:12:36.607 回答