在本机选项卡中调用onChnageTab函数时,如何将动态ID传递给选项卡

问题描述

我需要将items.id传递到OnChangeTab 我已经使用了native-base库中由索引插入的标签,我想发送动态ID,以便可以将相同的ID发送到我的api

   <Tabs
            // locked={true}
            tabBarUnderlinestyle={{backgroundColor: '#E60000'}}
            onChangeTab={({i}) => this.handleClickCat(i)}
            renderTabBar={() => <ScrollableTab />}>
            {this.props.data &&
              this.props.data.map((items,index) => {
                return (
                  <Tab
                    heading={
                      <Tabheading>
                        <TouchableOpacity
                          onPress={() => this.setState({id: items.id})}>
                          <Text>{items.title}</Text>
                        </TouchableOpacity>
                      </Tabheading>
                    }
                   key={items.id}
                    tabStyle={{backgroundColor: '#1D1E1F'}}
                    // onChangeTab={() => this.handleClickCat()}
                    // activeTab={() => this.setState({id: items.id})}
                    // o={this.setState({id: items.id})}
                    activeTabStyle={{backgroundColor: '#1D1E1F'}}
                    textStyle={{color: '#9E9E9E'}}
                    activeTextStyle={{color: '#FFFFFF'}}>
                    <AllNewsScrolimage
                      navigation={this.props.navigation}
                      data={this.props.catdata}
                      id={items.id}
                    />
                  </Tab>
                );
              })}
          </Tabs>

解决方法

i是标签的索引,因此您可以通过类似的操作获取项目的ID

handleClickCat(index){    
  const itemId = this.props.data[index].id; // Item id here
}

onChangeTab={({i}) => this.handleClickCat(i)}