react-native - 嵌套减速器不更新
问题描述
我有一个关于嵌套减速器的问题。
结构与此类似:
const INITIAL_STATE = {
items: [],
planningState:null,
loading: false,
idx_selected : '2'
};
在 state.items 中,结构是这样的:
const mockItems = [
{
date: "2018-08-24 15:00:00",
type: "dropoff",
status: null,
id: "553",
//many others things
},
{
date: "2018-08-24 19:00:00",
type: "pickup",
status: "ordered",
id: "553",
//other things
},
{
date: "2018-07-18 08:00:00",
type: "delivery",
status: null,
id: "554",
//other things
},
];
我需要更改一项的状态,而不更改其他属性。我知道我必须克隆每一层,但我犯了一个错误。
case SCAN_CLOSE_DONE:
//state.items[state.idx_selected].status=done
return{
...state,
items:{
...state.items,
[state.idx_selected]:{
...state.items[state.idx_selected],
status: "done"
}
}
};
解决方案
return {
...state,
items: state.items.map(item =>
{
...item,
status: "done"
}
)
}
推荐阅读
- oracle - 使用Mybatis 3.4.6 for Oracle Batch-Update 得到“-1”结果
- php - 删除 id 在逗号分隔字符串中的行
- mysql - 如何在 Ubuntu 19.04 (Disco Dingo) 中编辑 php.ini 文件
- arm - 如何将为目标设备 STM32F072B 编写的 STM32 片段(代码示例)转换为 STM32F030r8
- c# - Xceed DateTimePicker, isEnabled 时间选择器
- python - cx_Oracle.NotSupportedError:不支持元组类型的 Python 值
- python-3.x - 如果没有下一步按钮,只有编号可用,我如何转到下一页?
- python - 编写简单的 python 密码重置代码示例时遇到问题
- python - 为什么我们需要将 (R,1) 重塑为 (R,) 以进行绘图?
- angular - 在服务器上发送表单数据时面临问题