在执行时间内更改对象引用

时间:2019-04-04 05:24:10

标签: reactjs

我想在运行时使用React修改命令行。有可能吗?

示例: 在下面的语句中,我需要将客户修改为要在运行时定义的另一个对象:

blocks.customers.dataIndex = this.state.blocks.customers.dataIndex-1;

1 个答案:

答案 0 :(得分:0)

您可以使用其他...操作符来实现此目的,例如

示例

//In your case 
blocks.customers.dataIndex = {...this.state.blocks.customers.dataIndex-1};

//for arrays:
      const data = [{name:"max", age:30}] // assign this array into new array with additional object
      var abs =[...data,{name:"gyle",age:20}]; // rest operator create new copy of data array in abs and add new object

//for Objects:
      const data = {name:"max", age:30} //assign this array into new array with additional object
      var abs ={...data}; // rest operator create new copy of object in abs