How to pass multiple parameters to input's onChange handler

前端 未结 2 1266
执念已碎
执念已碎 2020-12-24 06:24

I render collection of input elements for objects in array.

render: function() {
    var ranges = [];
    this.props.ranges.map(function(range, index) {
             


        
相关标签:
2条回答
  • 2020-12-24 06:31

    I think this way is easier:

        <Input type="text"
                    value={range.name}
                    onChange={(e) => this.changeRangeName(range.id, e)}
            ...
        onChange(id, e) {
            ...
        }
    
    0 讨论(0)
  • 2020-12-24 06:34

    The event argument is still passed, but the rangeId argument is prepended to the arguments list, so your changeRangeName method would look like

    changeRangeName: function (rangeId, event) {
        var newName = event.target.value;
    },
    

    See Function.prototype.bind()

    0 讨论(0)
提交回复
热议问题