[英]Update nested state in redux without library
假設我有以下狀態。
let state = {
DirectoryMap :{
root :{
name : "root",
nested : null
},
........
........
},
currentDirectoryNode : null,
currentDirectory : 'root'
}
我想更新以下內容:
建議使用展平結構,但在這種情況下,由於權衡取舍,我無法做更多事情。
我想以不同的方式執行上述操作而不會改變原始狀態。 我也不想使用任何庫,例如immutable.js等。香草JS或ES6 / ES7功能可能會更好。
如果您使用的是jQuery,則可以執行以下操作,
let newState = jQuery.extend(true, {}, state);
另一種方式是
newState = JSON.parse(JSON.stringify(state));
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.