Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/413.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 react scrollTo不是一个函数_Javascript_Reactjs_Redux_Scroll_React Redux - Fatal编程技术网

Javascript react scrollTo不是一个函数

Javascript react scrollTo不是一个函数,javascript,reactjs,redux,scroll,react-redux,Javascript,Reactjs,Redux,Scroll,React Redux,我是新来的。这里我有一个表,其中有一些td,现在点击按钮,我在该表中添加了一个以上的td。现在,表格也可以滚动,所以,我想要的是,当我们添加新行时,表格滚动应该在顶部。因此,该用户将很容易知道该行已被添加 我试过的是 我有一个容器 JobList.js constructre(props){ super(props); this.myRef = React.createRef(); } componentDidMount() { if (this.state.opera

我是新来的。这里我有一个表,其中有一些
td
,现在点击按钮,我在该表中添加了一个以上的td。现在,表格也可以滚动,所以,我想要的是,当我们添加新行时,表格滚动应该在顶部。因此,该用户将很容易知道该行已被添加

我试过的是

我有一个容器

JobList.js

constructre(props){
    super(props);
    this.myRef = React.createRef();
}

componentDidMount() {
    if (this.state.operationType) {
      this.props.changeOperationType(this.state.operationType);
    }
    if (!this.props.jobs) {
      this.props.fetchUserJd();
    }
    this.myRef.current.scrollTo(0, 0);
  }


render() {
   return(
      <UserJobsTabel
              jobList={filteredList}
              sortAscending={this.sortData}
              sortCountAndScoreAscending={this.sortNumbersAscending}
              addNewRow={this.addNewRow}
              isRowAddingEditorVisible={this.props.isRowAddingEditorVisible}
              removeRow={this.removeRow}
              refer={this.myRef}/>
   )
}
<div className="table-responsive">
    <table>
    <thead>
     <tr className="text-center">
            <th></th>
            <th scope="col">Technology<i className="fa fa-fw fa-sort sort-icon"></i></th>
            <th scope="col">Total Resumes<i className="fa fa-fw fa-sort sort-icon"></i></th>
            <th scope="col">Job Title<i className="fa fa-fw fa-sort sort-icon"></i></th>
            <th scope="col">Total Score<i className="fa fa-fw fa-sort sort-icon"></i></th>
            <th scope="col">Average Score<i className="fa fa-fw fa-sort sort-icon"></i></th>
            <th></th>
          </tr>
</thead>
 <tbody className="text-center" ref={props.refer}>
 </tbody>
//remaining
   </div>
constructure(道具){
超级(道具);
this.myRef=React.createRef();
}
componentDidMount(){
if(this.state.operationType){
this.props.changeOperationType(this.state.operationType);
}
如果(!this.props.jobs){
this.props.fetchUserJd();
}
this.myRef.current.scrollTo(0,0);
}
render(){
返回(
)
}
UserJobsTable.js

constructre(props){
    super(props);
    this.myRef = React.createRef();
}

componentDidMount() {
    if (this.state.operationType) {
      this.props.changeOperationType(this.state.operationType);
    }
    if (!this.props.jobs) {
      this.props.fetchUserJd();
    }
    this.myRef.current.scrollTo(0, 0);
  }


render() {
   return(
      <UserJobsTabel
              jobList={filteredList}
              sortAscending={this.sortData}
              sortCountAndScoreAscending={this.sortNumbersAscending}
              addNewRow={this.addNewRow}
              isRowAddingEditorVisible={this.props.isRowAddingEditorVisible}
              removeRow={this.removeRow}
              refer={this.myRef}/>
   )
}
<div className="table-responsive">
    <table>
    <thead>
     <tr className="text-center">
            <th></th>
            <th scope="col">Technology<i className="fa fa-fw fa-sort sort-icon"></i></th>
            <th scope="col">Total Resumes<i className="fa fa-fw fa-sort sort-icon"></i></th>
            <th scope="col">Job Title<i className="fa fa-fw fa-sort sort-icon"></i></th>
            <th scope="col">Total Score<i className="fa fa-fw fa-sort sort-icon"></i></th>
            <th scope="col">Average Score<i className="fa fa-fw fa-sort sort-icon"></i></th>
            <th></th>
          </tr>
</thead>
 <tbody className="text-center" ref={props.refer}>
 </tbody>
//remaining
   </div>

技术
总简历
职位名称
总分
平均分
//剩余的
所以,这里我得到了一个错误,scrollTo不是一个函数


那么,有没有办法做到这一点?或者我做错了什么。

您能尝试将ref={props.reference}从tbody更改为表的div吗? 这样地:

据我所知,react的滚动条可以与div一起使用,或者它需要一些插件,比如jQueryOE窗口

无论如何,您也可以尝试以下方法(在最后一种情况下,仅供参考,这不是一个好的选择): document.body.scrollTo()

供进一步参考:

您能尝试将ref={props.refere}从tbody更改为table的div吗? 这样地:

据我所知,react的滚动条可以与div一起使用,或者它需要一些插件,比如jQueryOE窗口

无论如何,您也可以尝试以下方法(在最后一种情况下,仅供参考,这不是一个好的选择): document.body.scrollTo()

供进一步参考:
因为
this.myRef
获取
UserJobsTabel
的实例。您可以改为转发引用


因为
this.myRef
获取
UserJobsTabel
的实例。您可以改为转发引用


使用
this.myRef.current?.getNode().scrollTo({x:0,y:0})
使用
this.myRef.current?.getNode().scrollTo({x:0,y:0})
this.myRef
定义在哪里?要使用新的ref系统,必须在构造函数中调用
this.myRef=React.createRef()我已将其添加到构造函数中,或者@dotconnor已更新questtion@tanmay很抱歉,我没有找到您,而是调用了
scrollTo
function assign
scrollTop
param。比如
this.myRef.current.scrollTop=0
在哪里定义了
this.myRef
?要使用新的ref系统,必须在构造函数中调用
this.myRef=React.createRef()我已将其添加到构造函数中,或者@dotconnor已更新questtion@tanmay很抱歉,我没有找到您,而是调用了
scrollTo
function assign
scrollTop
param。像
this.myRef.current.scrollTop=0
这就是为什么最后一个选项是document.body.scrollTo(),这就是为什么最后一个选项是document.body.scrollTo()