Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/react-native/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
React native 我正在使用react native swiper flatlist,但我不知道如何在按下按钮时使用scrollToIndex_React Native_Swiper - Fatal编程技术网

React native 我正在使用react native swiper flatlist,但我不知道如何在按下按钮时使用scrollToIndex

React native 我正在使用react native swiper flatlist,但我不知道如何在按下按钮时使用scrollToIndex,react-native,swiper,React Native,Swiper,我使用的是react native swiper flatlist,我想通过点击按钮向前滚动到某个索引,但不知道如何操作。虽然我是一个非常初学者,以反应本地开发 我已经搜索了很多,但没有任何帮助,我得到了一个错误:undefined不是对象this2.swiper.scrollToIndex' render() { return ( <View style={styles.container}> <SwiperFlatList ref={swiper =

我使用的是react native swiper flatlist,我想通过点击按钮向前滚动到某个索引,但不知道如何操作。虽然我是一个非常初学者,以反应本地开发

我已经搜索了很多,但没有任何帮助,我得到了一个错误:undefined不是对象this2.swiper.scrollToIndex'

render() {
return (
  <View style={styles.container}>
    <SwiperFlatList
      ref={swiper => {
        this.swiper = swiper;
      }}
      data={[
        { key: "a" },
        { key: "b" },
        { key: "c" },
        { key: "d" },
        { key: "e" }
      ]}
      index={0}
      renderItem={({ item, index }) => (
        <View>
          <Image
            style={styles.child}
            source={require("../../assets/advertisementtwo.png")}
          />
          <Image
            style={styles.child}
            source={require("../../assets/advertisementtwo.png")}
          />
          <Image
            style={styles.child}
            source={require("../../assets/advertisementtwo.png")}
          />
          <Image
            style={styles.child}
            source={require("../../assets/advertisementtwo.png")}
          />
          <Button
            title={"Next"}
            onPress={this.swiper.scrollToIndex(1, true)}
            style={{ backgroundColor: "white" }}
          />
        </View>
      )}
    />
  </View>
);
render(){
返回(
{
this.swiper=swiper;
}}
资料={[
{key:“a”},
{键:“b”},
{键:“c”},
{键:“d”},
{键:“e”}
]}
索引={0}
renderItem={({item,index})=>(
)}
/>
);
}

应该在按钮点击时滑动吗


尝试将
ref='swiper'
添加为
swiperplatlist
prop

示例

<SwiperFlatList ref='swiper'/>


this.refs.swiper.\u scrollToIndex(2)

我已经解决了问题“onPress={this.swiper.scrollToIndex(3)}”应该替换为onPress={()=>{this.refs.swiper.\u scrollToIndex(3)}谢谢您需要设置
this.refs.swiper.scrollToIndex(2)
,并声明引用作为示例