对ReactJS中的子项绑定组件的警告

时间:2015-08-27 15:59:35

标签: javascript reactjs

我在桌面上有几个警告,其中有控件在单元格内。如果我点击一个单元格,就会发生一个事件。某些单元格具有菜单下拉列表和事件,具体取决于选择。我将一个值绑定到onClick事件,以便我可以在我的函数中获取一个值。

我的每一行都收到以下警告: 警告:bind():React组件方法只能绑定到组件实例。

我的代码如下所示:

  items = this.state.currentValues.map(function(itemVal) {
      return (
          <tr>
            <td  onClick={this.rowClick.bind(this, itemVal.OrderId)}>{itemVal.Customer}</td>
            <td  onClick={this.rowClick.bind(this, itemVal.OrderId)}>{itemVal.OrderId}</td>
            <td>
              <div> Flag To Group </div>
              <div>
                <Menu label={itemVal.User}>
                  <List onSelect={this.assignResponsibleUser.bind(this, itemVal.User)}>
                  </List>
                </Menu>
              </div>
          </td>
          </tr>
        );
    }.bind(this)
    );
    return(
        <Table selectable={true} scrollable={true} small={true}>
            <tr>
                {tableHeader}
            </tr>
            <tbody>
                {items}
            </tbody>
        </Table>
    );

我尝试更换:

onClick={this.rowClick.bind(this, itemVal.OrderId)}

onClick={this.rowClick.bind(null, itemVal.OrderId)}

但它给了我同样的警告。

我尝试删除.bind(this)但是它给了我一个错误,因为它找不到rowClick函数。

如何解决此问题?

2 个答案:

答案 0 :(得分:0)

而不是使用

this

使用

while(cur->next !=NULL && cur->next->type != XML_ELEMENT_NODE) {
    cur = cur->next;
}
// at this point, the next element, if it exists, is of type XML_ELEMENT_NODE
// if it doesn't exist, cur->next will be NULL
cur = cur->next;

它是传递范围的地图选项。

答案 1 :(得分:0)

this.method必须是一个函数,如:

senddel:function(id){
      this.props.onCommentDel(id);//parent callback
    },
    render: function() {
        return ( < div className = "commentList" >
            {this.props.data.map(function(comment){
                return (
                    <Comment key={comment.id} author={comment.author} onCommentDel={this.senddel.bind(this,comment.id)}>
                    {comment.text}
                    </Comment>
                )
            },this)}
    < /div>
    );
}