我想阅读onClick事件值属性。但是当我单击它时,在控制台上会看到类似以下的内容:
SyntheticMouseEvent {dispatchConfig: Object, dispatchMarker: ".1.1.0.2.0.0:1", nativeEvent: MouseEvent, type: "click", target
我的代码正常工作。运行时,我可以{column}
在onClick事件中看到但无法获取它。
我的代码:
var HeaderRows = React.createClass({
handleSort: function(value) {
console.log(value);
},
render: function () {
var that = this;
return(
<tr>
{this.props.defaultColumns.map(function (column) {
return (
<th value={column} onClick={that.handleSort} >{column}</th>
);
})}
{this.props.externalColumns.map(function (column) {
// Multi dimension array - 0 is column name
var externalColumnName = column[0];
return ( <th>{externalColumnName}</th>);
})}
</tr>
);
}
});
如何onClick
在React js中将值传递给事件?
You just need to use Arrow function to pass value.
<button onClick={() => this.props.onClickHandle("StackOverFlow")}>
Make sure to use () = >, Otherwise click method will be called without click event.
Note : Crash checks default methods
Please find below running code in codesandbox for the same.
React pass value with method