我有一个JSON对象数组,并希望在状态更新
现状是
this.state.data has [
{
"check_box_list": [
{"name":"Courier Received by Investor","value":true},
{"name":"Courier Sent By Investor","value":true},
{"name":"Signed CA-Doc received","value":true},
{"name":"Cheque/Payment Received","value":true},
{"name":"Cancelled Cheque Received","value":true},
{"name":"ID Proof Received","value":true},
{"name":"Address Proof Received","value":true},
{"name":"KYC Received","value":true},
{"name":"Signed CA pictures/scan received","value":true},
{"name":"KRA Updated","value":true}
],
"ca_doc_offline_comment":[""],
"_id":"5ca89fcd0434ff4ba08b2d37",
"user_id":"1589",
"investor_name":"Anupam Mittal",
"source":"Banner",
"completed_check_box_list":false,
"investment_information_id":1154
},
...etc
]
想要用过滤后的数据替换状态:
var filtered_data = [
{
check_box_list: [
{ name: "Courier Received by Investor", value: false },
{ name: "Courier Sent By Investor", value: false },
{ name: "Signed CA-Doc received", value: false },
{ name: "Cheque/Payment Received", value: false },
{ name: "Cancelled Cheque Received", value: false },
{ name: "ID Proof Received", value: false },
{ name: "Address Proof Received", value: false },
{ name: "KYC Received", value: false },
{ name: "Signed CA pictures/scan received", value: false },
{ name: "KRA Updated", value: false },
{ name: "KYC Updated", value: false }
],
ca_doc_offline_comment: [""],
_id: "5ca987f8198d13a54714789e",
investor_name: "Samala Sumanth",
completed_check_box_list: false
},
{
check_box_list: [
{ name: "Courier Received by Investor", value: false },
{ name: "Courier Sent By Investor", value: false },
{ name: "Signed CA-Doc received", value: false },
{ name: "Cheque/Payment Received", value: false },
{ name: "Cancelled Cheque Received", value: false },
{ name: "ID Proof Received", value: false },
{ name: "Address Proof Received", value: false },
{ name: "KYC Received", value: false },
{ name: "Signed CA pictures/scan received", value: false },
{ name: "KRA Updated", value: false },
{ name: "KYC Updated", value: false }
],
ca_doc_offline_comment: [""],
_id: "5ca98801198d13a54714789f",
investor_name: "Samala Sumanth",
completed_check_box_list: false
}
];
尝试过不变的帮助包和对象分配似乎没什么工作可以请你帮我解答,提前谢谢
你可以做:
const clonedArray = JSON.parse(JSON.stringify(myArray))
然后使用map
更新clonedArray
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map