Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.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
List ScrolltoIndex在平面列表上不工作_List_React Native_Scroll_React Native Flatlist - Fatal编程技术网

List ScrolltoIndex在平面列表上不工作

List ScrolltoIndex在平面列表上不工作,list,react-native,scroll,react-native-flatlist,List,React Native,Scroll,React Native Flatlist,我使用一个flatList来呈现json文件中的项目,我想在按下按钮时滚动到一个特定的索引,我声明了按钮按下的函数,如下所示 goIndex = () => { this.flatListRef.scrollToIndex({animated: true,index:5}); }; 虽然没有显示任何错误,但列表没有移动到指定的索引 反应本机:0.55.4 随附平面图编号 <View> <FlatList getItemLayout=

我使用一个
flatList
来呈现json文件中的项目,我想在按下按钮时滚动到一个特定的索引,我声明了按钮按下的函数,如下所示

goIndex = () => {
    this.flatListRef.scrollToIndex({animated: true,index:5});
};
虽然没有显示任何错误,但列表没有移动到指定的索引

反应本机:0.55.4

随附平面图编号

<View>
    <FlatList   
        getItemLayout={(data, index) => { return {length: 33, index, offset: 33 * index} }}
        ItemSeparatorComponent={ () => <View style={ { width:"100%", height: .7, backgroundColor: 'rgba( 52,52,52,1)' } } /> }
        data={this.state.outverse}
        renderItem={({item,index}) =>
            <View style={styles2.flatview}>
                <Text style={styles2.name}>{++index}  {item} </Text>
            </View>
        }
    />
</View>

{返回{length:33,index,offset:33*index}}
ItemSeparatorComponent={()=>}
数据={this.state.outverse}
renderItem={({item,index})=>
{++index}{item}
}
/>

尝试添加对
平面列表的引用,如下所示:

<View>
    <FlatList   
        getItemLayout={(data, index) => { return {length: 33, index, offset: 33 * index} }}
        ItemSeparatorComponent={ () => <View style={ { width:"100%", height: .7, backgroundColor: 'rgba( 52,52,52,1)' } } /> }
        data={this.state.outverse}
        ref={(ref) => { this.flatListRef = ref; }}
        renderItem={({item,index}) =>
            <View style={styles2.flatview}>
                <Text style={styles2.name}>{++index}  {item} </Text>
            </View>
        }
    />
</View>
请尝试以下操作:

<FlatList
        style={{
          marginLeft: 50,
          paddingTop: 0,
          paddingRight: 0
        }}
        ref={ref => {
          this.flatList_Ref = ref;  // <------ ADD Ref for the Flatlist 
        }}
        removeClippedSubviews={false}
        enableEmptySections={false}
        data={this.props.list}
        keyExtractor={this._keyExtractor}
        renderItem={this._renderItem1}
        ItemSeparatorComponent={this._renderSeparator}

      />

什么是
this.flatListRef
?它指的是代码中定义的平面列表。请共享有问题的组件代码itself@AravindS是的把它附在问题上你只分享了一部分,请全部分享component@kiran:我按照您的代码实现,但当我参考此.flatlistRef时,我没有得到任何与flatlist相关的方法。有什么问题吗?@Tejas你在说这个吗?@KirankumarDafda:是的,这些方法都不可访问,我使用的是react native的0.55.4版本。我不知何故通过“ref.\u reactInternalFiber.child.stateNode.scrollToIndex()”访问了scrollToIndex(),但这也不起作用。你能帮我一下吗。goIndex=()=>{this.flatListRef.scrollToIndex({动画:true,索引:5});};删除参考值对我很有效。谢谢。我们在哪里调用goIndex方法?
<FlatList
        style={{
          marginLeft: 50,
          paddingTop: 0,
          paddingRight: 0
        }}
        ref={ref => {
          this.flatList_Ref = ref;  // <------ ADD Ref for the Flatlist 
        }}
        removeClippedSubviews={false}
        enableEmptySections={false}
        data={this.props.list}
        keyExtractor={this._keyExtractor}
        renderItem={this._renderItem1}
        ItemSeparatorComponent={this._renderSeparator}

      />
goIndex = () => {

 this.flatList_Ref.scrollToIndex({animated: true,index:5});

};