我想读取并显示 .txt 文件中的文本内容,该文件使用 React Native 本地保存到应用程序构建中。
文本很大,因此我无法将其硬编码到代码中。
我正在使用a flatList从json文件渲染项目,我想在按下按钮时滚动到特定索引,我声明了按下按钮的功能,如下所示
goIndex = () => {
this.flatListRef.scrollToIndex({animated: true,index:5});
};
Run Code Online (Sandbox Code Playgroud)
尽管它没有显示任何错误,但是列表没有移动到指定的索引。
反应本机:0.55.4
FlatList的附加代码。
<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>
Run Code Online (Sandbox Code Playgroud)