Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/25.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
Json 如何更新react js中嵌套对象的状态,在我的示例中是DeviceProperties(IPAddress、username和password)_Json_Reactjs_State - Fatal编程技术网

Json 如何更新react js中嵌套对象的状态,在我的示例中是DeviceProperties(IPAddress、username和password)

Json 如何更新react js中嵌套对象的状态,在我的示例中是DeviceProperties(IPAddress、username和password),json,reactjs,state,Json,Reactjs,State,如何更新react js中嵌套对象的状态,在我的示例中是DeviceProperties(IPAddress、username和password) 在减速器中: [...] case UPDATE_DEVICE_PROPERTIES: return { ...device, DeviceProperties: { [...] } } break; [...] 在这个例子中,我展示了如何更新一个设备,如果你已经选择了这个设备。在访问时,您将遍历设备[]-数组并找到正确的设

如何更新react js中嵌套对象的状态,在我的示例中是DeviceProperties(IPAddress、username和password)

在减速器中:

[...]
case UPDATE_DEVICE_PROPERTIES:
  return {
    ...device,
    DeviceProperties: { [...] }
  }
break;
[...]
在这个例子中,我展示了如何更新一个设备,如果你已经选择了这个设备。在访问时,您将遍历设备[]-数组并找到正确的设备。然后您将使用对象分解(三点…对象,例如…设备)仅更新必要的部分

有关对象分解的详细信息:

用于更新对象的官方redux文档:

您可以使用点表示法访问嵌套对象值,例如
设备属性.IPAddress
。例如,如果您试图仅存储IPAddress,则可以使用


this.setState({IPAddress:DeviceProperties.IPAddress})

使用setState进行完整的objectdeviceSettings:{名称:'',//设备ID:null,iPAddress:'',用户名:'',密码:'',//名称:this.props.device.name,//设备ID:this.props.device.deviceId,//iPAddress:this.props.device.deviceProperties.iPAddress,//用户名:this.props.device.deviceProperties.userName,//密码:this.props.device.deviceProperties.Password,序列号:'',pairedNetworkName:'',说明:'',设备ID:'',},我在我的状态中有类似的设置,无法删除设备设置,因为我正在reducers和sagaso中使用它。从这一点开始,我如何使用设备设置访问IPAddress、用户名和密码您可以使用deviceSettings.IPAddressSyntax访问IPAddress。设置状态({'deviceSettings.IPAddress':DeviceProperties.IPAddress})
[...]
case UPDATE_DEVICE_PROPERTIES:
  return {
    ...device,
    DeviceProperties: { [...] }
  }
break;
[...]