Javascript 如何解决错误?:node.scrollTo不是一个函数
当我在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)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
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, ...})