angular - NGRX - 如何通过reducer更新数组中对象中的字段?
问题描述
如何通过reducer更新数组中的字段?我试过这个:
const customers = state.filteredCustomers;
for (const customer of customers) {
for (const addr of customer.addresses) {
addr.selected = false;
}
}
return {
...state,
filteredCustomers: customers,
};
但它会抛出一个错误:
TypeError: Cannot assign to read only property 'selected' of object '[object Object]'
做这个的最好方式是什么?
解决方案
import _ from 'lodash';
并在您的代码中使用
const tags: IAreaTag[] = _.cloneDeep(department.tags);
然后返回常量
所以在你的代码中
const customers = _.cloneDeep(state.filteredCustomers);
推荐阅读
- python-3.x - 如何在 tkinter 的文本小部件中获取一行字符?
- node.js - 如何检查用户是否已登录?Passport 和 discord oAuth2 (EJS)
- discord - 为什么 discord.py 无法正常运行?(设置)
- c - 指针/结构 free() - 堆损坏
- python - 在 Python 中的 dict 内的列表中搜索 - Pymongo
- javascript - 从构造函数中确定 tagName
- nginx - Nginx 代理通行证不渲染
- r - 如何根据不同的类找到多少个唯一值
- spring-boot - Spring Cloud Contract:在运行时找不到本地合约生成存根
- java - HQL查询左连接和带有数组的bean