Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/google-chrome/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
React native 如何传递分区列表';s滚动到子组件的位置?_React Native_Sections - Fatal编程技术网

React native 如何传递分区列表';s滚动到子组件的位置?

React native 如何传递分区列表';s滚动到子组件的位置?,react-native,sections,React Native,Sections,我正在构建一个React本机应用程序,它有一个用户需要填写的流程指南。当用户选择了一个选项后,我想让他在屏幕上向下滚动到新选项出现的位置 为了实现这一点,我需要在按钮的onClick中提供SectionList的功能 42 const sectionData = [ 43 { 44 data: [ 45 { 46 key: "1", 47 program: [ 48 <Question 49

我正在构建一个React本机应用程序,它有一个用户需要填写的流程指南。当用户选择了一个选项后,我想让他在屏幕上向下滚动到新选项出现的位置

为了实现这一点,我需要在按钮的onClick中提供SectionList的功能

 42 const sectionData = [
 43   {
 44     data: [
 45       {
 46         key: "1",
 47         program:  [
 48           <Question
 49             key={1}
 50             onAnswerSubmit={() => {
 51               scrollToLocation(1);
       /* 
           How do I access scrollToLocation from 
           SectionList and pass it along as a prop here?
        */
 52             }}
 53           />,
 54           <Question
 55             key={2}
 56             onAnswerSubmit={() => {
 57               scrollToLocation(1);
 58             }}


130   public render() {
131
132     return (
133       <SectionList
135         sections={ sectionData }
136         renderItem={ renderItem }
137         renderSectionHeader={ sectionHeader }
138         keyExtractor={ keyExtractor }
139       >
140       </SectionList>
42 const sectionData=[
43   {
44数据:[
45       {
46键:“1”,
47方案:[
48            {
51滚动定位(1);
/* 
如何从中访问scrollToLocation
把它作为道具传递到这里?
*/
52             }}
53           />,
54            {
57个位置(1);
58             }}
130公共渲染(){
131
132返回(
133
140
问题。tsx

 28   public render() {
 29     return (
 30       <Question
 31         {...this.props}
 32         onPress={this.props.onAnswerSubmit}
 33       />
 34     );
28公共呈现(){
29返回(
30
34     );

您可以像这样将ref添加到SectionList中

ref = "foo"
叫它

this.refs.foo.scrollToLocation(params);
this.sectionListRef.scrollToLocation(params);

叫它

this.refs.foo.scrollToLocation(params);
this.sectionListRef.scrollToLocation(params);