相关疑难解决方法(0)

React js onClick无法将值传递给方法

我想阅读onClick事件值属性.但是当我点击它时,我在控制台上看到类似的东西:

SyntheticMouseEvent {dispatchConfig: Object, dispatchMarker: ".1.1.0.2.0.0:1", nativeEvent: MouseEvent, type: "click", target
Run Code Online (Sandbox Code Playgroud)

我的代码工作正常.当我运行时,我可以看到{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>
    );
  }
});
Run Code Online (Sandbox Code Playgroud)

如何将值传递给onClickReact js中的事件?

javascript reactjs

563
推荐指数
14
解决办法
46万
查看次数

将多个参数传递给React中的事件处理程序

所以我试图使反应与ES6语法一起工作.在ES5中,我有setInitialState,没有使用函数绑定语法的构造函数.我有一个价格列表是任意的,我希望状态在输入元素改变时改变.但是必须改变合适的价格.

我甚至不确定这是正确的做法.有人可以告诉我这应该做的最新方式吗?

这是我的代码:

import React, {Component} from 'react'
import 'bootstrap/dist/css/bootstrap.css';

export default class PriceTable extends Component {
  constructor(props, context) {
    super(props, context);

    this.state = {
      pid: this.props.pid || "12345",
      name: this.props.name || "name",
      prices: this.props.prices || [
        {count: 1, desc: 'one', price: 8.25},
        {count: 6, desc: 'six', price: 7.60},
        {count: 12, desc: 'twelve', price: 6.953}
      ]
    };

    this.setPid = this.setPid.bind(this);
    this.setName = this.setName.bind(this);
    this.setCount = this.setCount.bind(this, i);
    this.setDesc = this.setDesc.bind(this, i);
    this.setPrice = this.setPrice.bind(this, i);
    this.logDebug = this.logDebug.bind(this);
  }

  setPid(e) …
Run Code Online (Sandbox Code Playgroud)

reactjs twitter-bootstrap-3

4
推荐指数
1
解决办法
1万
查看次数

标签 统计

reactjs ×2

javascript ×1

twitter-bootstrap-3 ×1