React js onClick can't pass value to method

后端 未结 30 2348
北荒
北荒 2020-11-22 07:05

I want to read the onClick event value properties. But when I click on it, I see something like this on the console:

SyntheticMouseEvent {dispatchConfig: Ob         


        
30条回答
  •  南旧
    南旧 (楼主)
    2020-11-22 07:24

    I have added code for onclick event value pass to the method in two ways . 1 . using bind method 2. using arrow(=>) method . see the methods handlesort1 and handlesort

    var HeaderRows  = React.createClass({
        getInitialState : function() {
          return ({
            defaultColumns : ["col1","col2","col2","col3","col4","col5" ],
            externalColumns : ["ecol1","ecol2","ecol2","ecol3","ecol4","ecol5" ],
    
          })
        },
        handleSort:  function(column,that) {
           console.log(column);
           alert(""+JSON.stringify(column));
        },
        handleSort1:  function(column) {
           console.log(column);
           alert(""+JSON.stringify(column));
        },
        render: function () {
            var that = this;
            return(
            
    Using bind method
    {this.state.defaultColumns.map(function (column) { return (
    {column}
    ); })}
    Using Arrow method
    {this.state.defaultColumns.map(function (column) { return (
    that.handleSort1(column)} >{column}
    ); })} {this.state.externalColumns.map(function (column) { // Multi dimension array - 0 is column name var externalColumnName = column; return (
    {externalColumnName}
    ); })}
    ); } });

提交回复
热议问题