首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >主反应表中的按钮不工作

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

Stack Overflow用户
提问于 2018-04-29 08:05:46
回答 1查看 3.6K关注 0票数 0

我使用素数react创建一个表,表的最后一列用于表上可以执行的操作,但是我跟踪文档,但是onClick事件在按钮上不起作用。当我单击“搜索”按钮时,会得到一个错误:"UserList.js:19 Uncaught TypeError:_this2.selectUser不是函数“

有线索吗?

守则:

代码语言:javascript
运行
复制
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>
        );
      }
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-04-29 08:45:03

尝试:

代码语言:javascript
运行
复制
<Column body={this.actionTemplate.bind(this)} header="Actions" style={{ textAlign: 'center', width: '6em' }} />

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

票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50084575

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档