Javascript 主反应表中的按钮不工作

Javascript 主反应表中的按钮不工作,javascript,reactjs,primereact,Javascript,Reactjs,Primereact,我正在使用prime react创建一个表,表的最后一列是可以在表上执行的操作,但是我在跟踪文档,但是onClick事件在按钮上不起作用。当我点击搜索按钮时,我得到一个错误:“UserList.js:19 uncaughttypeerror:\u this2.selectUser不是一个函数” 有什么线索吗 守则: actionTemplate(rowData, column) { console.log('column', column); console.log('rowDa

我正在使用prime react创建一个表,表的最后一列是可以在表上执行的操作,但是我在跟踪文档,但是onClick事件在按钮上不起作用。当我点击搜索按钮时,我得到一个错误:“UserList.js:19 uncaughttypeerror:\u this2.selectUser不是一个函数”

有什么线索吗

守则:

actionTemplate(rowData, column) {
    console.log('column', column);
    console.log('rowData', rowData);
    return (<div>
      <Button
        type="button" icon="fa-search"
        className="ui-button-success" onClick={() => this.selectUser(1)}
      />
      <Button
        type="button" icon="fa-edit"
        className="ui-button-warning"
      />
    </div>);
  }

  selectUser(userId) {
    console.log('selectUser');
    userId = 1;
    this.props.actions.fetchUser(userId);
  }


    renderTable() {
        const paginatorLeft = <Button icon="fa-refresh" />;
            /* const users = [
                    { name: '1', email: '1981', updateDate: '', creationDate: '05/03/2016' },
                    { name: '2', email: '1982', updateDate: '', creationDate: '04/02/2017' },
            ]; */
        const { users } = this.props;
        return (
          <DataTable
            value={users} paginator paginatorLeft={paginatorLeft}
            rows={10} rowsPerPageOptions={[5, 10, 20]}
          >
            <Column field="name" header="Name" filter style={{ textAlign: 'center', width: '6em' }} />
            <Column field="email" header="Email" filter style={{ textAlign: 'center', width: '6em' }} />
            <Column field="lastUpdate" header="Last update" style={{ textAlign: 'center', width: '6em' }} />
            <Column field="creationDate" header="Creation Date" style={{ textAlign: 'center', width: '6em' }} />
            <Column body={this.actionTemplate} header="Actions" style={{ textAlign: 'center', width: '6em' }} />
          </DataTable>
        );
      }
actionTemplate(行数据,列){
console.log('column',column);
console.log('rowData',rowData);
返回(
选择此选项。选择用户(1)}
/>
);
}
选择用户(userId){
console.log('selectUser');
userId=1;
this.props.actions.fetchUser(userId);
}
可渲染的(){
常数paginatorLeft=;
/*常量用户=[
{名称:'1',电子邮件:'1981',更新日期:'',创建日期:'05/03/2016'},
{名称:'2',电子邮件:'1982',更新日期:'',创建日期:'04/02/2017'},
]; */
const{users}=this.props;
返回(
);
}
试试:


我猜actionTemplate是在另一个对象上下文中调用的,这就是为什么没有定义函数的原因。

请尝试:



我猜actionTemplate是在另一个对象上下文中调用的,这就是为什么
selectUser
没有定义/a函数。

查看组件的开头会很有帮助。最后。假设您将babel设置为传输此文件,将
selectUser(userId){…
定义更改为
selectUser=userId=>{…
将有助于查看组件的开头和结尾。假设您将babel设置为传输此文件,则更改
selectUser(userId){…
定义到
selectUser=userId=>{…
<Column body={this.actionTemplate.bind(this)} header="Actions" style={{ textAlign: 'center', width: '6em' }} />