Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/460.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
Javascript 如何解决错误?:node.scrollTo不是一个函数_Javascript_Node.js_Reactjs_React Native - Fatal编程技术网

Javascript 如何解决错误?:node.scrollTo不是一个函数

Javascript 如何解决错误?:node.scrollTo不是一个函数,javascript,node.js,reactjs,react-native,Javascript,Node.js,Reactjs,React Native,当我在TodoItem组件中运行onPress时,我希望执行scrollTo并向下滚动y:height值 但如果我跑新闻界 node.scrollTo不是一个函数{ const height=维度.get('window')。高度; const[tabIndex,setTabIndex]=useState(0); const flatListRef=React.useRef() const refScrollView=createRef(); 返回( ( { const node=refScro

当我在TodoItem组件中运行onPress时,我希望执行scrollTo并向下滚动y:height值

但如果我跑新闻界

node.scrollTo不是一个函数{ const height=维度.get('window')。高度; const[tabIndex,setTabIndex]=useState(0); const flatListRef=React.useRef() const refScrollView=createRef(); 返回( ( { const node=refScrollView.current; 如果(节点){ scrollTo({x:0,y:height,animated:true}); } }} /> )} /> (TodoItem.js)

import React,{useCallback,useState}来自“React”;
从“react native”导入{FlatList};
const TodoItem=({onPress})=>{
返回(
你好

我不知道为什么会发生此错误。如何修复我的代码?我想使用FlatList

FlatList
Github源代码中,我只能看到4种有助于滚动功能的方法:-

scrollToEnd(params?: ?{animated?: ?boolean, ...})
我认为您需要使用上述任一项(因为
FlatList
没有实现它自己的
scrollTo
)。我可以在
VirtualizedList
中看到
scrollTo
的用法,它是由
FlatList
内部返回的


链接到源代码-

您可以尝试使用以下内容:


node.scrollIntoView({behavior:'smooth',block:'start'})

存在于
node
中的对象显然没有
scrollTo
方法。比你!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1
        import React, { useCallback, useState } from 'react';
        import {FlatList} from 'react-native';


        const TodoItem = ({onPress}) => {


        return (
            
        
        <MainContainer onPress={onPress}>
            <Label>hi</Label>
        </MainContainer>
scrollToEnd(params?: ?{animated?: ?boolean, ...})
scrollToIndex(params: {
    animated?: ?boolean,
    index: number,
    viewOffset?: number,
    viewPosition?: number,
    ...
  })
scrollToItem(params: {
    animated?: ?boolean,
    item: ItemT,
    viewPosition?: number,
    ...
  })
scrollToOffset(params: {animated?: ?boolean, offset: number, ...})