1

这是表类,我试图在表选项中返回行数据对象 onRowClick。当我记录所有三个参数时,对象返回空。索引和单击事件 console.log 完美地返回这个here is the event: Proxy {dispatchConfig: Object, _targetInst: ReactDOMComponent, _dispatchInstances: ReactDOMComponent, nativeEvent: MouseEvent, type: "click"…} the index: 0 the object: Object {}有人知道为什么或如何获取返回的数据吗?也许使用不同的功能?

class BPTable extends React.Component {
constructor(props) {
super(props);
    // console.log(props.result);
}

logArgs(event,index,object){
console.log('here is the event:',event,'the index:',index, 'the object:',object);
}

render() {
//reset the state of BP Data on search click. 
this.state = {
  bpTableData: [
  ],
};
//creation of each data object to display
for (var i = 0; i < this.props.result.length; i++) {
    this.state.bpTableData.push({
        cc: this.props.result[i]['CardCode'],
        name: this.props.result[i]['BPName'],
        cPerson: this.props.result[i]['ContactPerson'],
        address: this.props.result[i]['Address'],
        email: this.props.result[i]['Email']
    });
}

return (
    <Table 
        onRowClick={this.logArgs}
        rowsCount={this.state.bpTableData.length}
        rowHeight={50}
        headerHeight={50}
        width={1200}
        height={1000}
        {...this.props}>
    <Column 
      header={<Cell>Card Code</Cell>}
      cell={props => (
        <Cell {...props}
        data={this.state.bpTableData[props.rowIndex].cc}>
          {this.state.bpTableData[props.rowIndex].cc}
        </Cell>

      )}
      width={200}
    />        
    <Column
      header={<Cell>Buisness Name</Cell>}
      cell={props => (
        <Cell {...props}
          data = {this.state.bpTableData[props.rowIndex].name}
        >
          {this.state.bpTableData[props.rowIndex].name}
        </Cell>

      )}
      width={200}
    /> 
    <Column
      header={<Cell>Contact Person</Cell>}
      cell={props => (
        <Cell {...props}>
          {this.state.bpTableData[props.rowIndex].cPerson}
        </Cell>

      )}
      width={200}
    />                
    <Column
      header={<Cell>Address</Cell>}
      cell={props => (
        <Cell {...props}>
          {this.state.bpTableData[props.rowIndex].address}
        </Cell>

      )}
      width={400}
    />        
    <Column
      header={<Cell>Email</Cell>}
      cell={props => (
        <Cell {...props}>
          {this.state.bpTableData[props.rowIndex].email}
        </Cell>

      )}
      width={100}
    />
  </Table>
);
}
4

1 回答 1

4

看起来 onRowClick 只有参数:事件,索引。我通过使用索引来访问我作为状态的一部分创建的适当的表数据来解决这个问题。

在您的情况下,它将是:

logArgs(event,index){
  console.log( 'here is the event:',event,
               'the index:',index,
               'the object:',this.state.bpTableData[index]
  );
}
于 2016-08-30T13:25:58.390 回答