Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/458.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/heroku/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在React内的setState中传入参数_Javascript_Reactjs - Fatal编程技术网

Javascript 在React内的setState中传入参数

Javascript 在React内的setState中传入参数,javascript,reactjs,Javascript,Reactjs,如何删除setState中的硬代码0并使用索引驱动该代码 要将索引用作大括号的对象键换行: handleUpdateRingers(index, event) { this.setState({ items: update(this.state.items, {0: {ringerNumbers: {$set: event.target.value}}}) }, () => this.updateTotals()) 然后,请将答案标记为正确: handl

如何删除setState中的硬代码0并使用索引驱动该代码

要将索引用作大括号的对象键换行:

  handleUpdateRingers(index, event) {

    this.setState({
      items: update(this.state.items, {0: {ringerNumbers: {$set: event.target.value}}})
    }, () => this.updateTotals())

然后,请将答案标记为正确:
handleUpdateRingers(index, event) {

    this.setState({
      items: update(this.state.items, {[index]: {ringerNumbers: {$set: event.target.value}}})
    }, () => this.updateTotals())