google-chrome-extension - 如何更新嵌套对象内 LocalStorage 中的某个值?
问题描述
我这样设置:
chrome.storage.local.set({
myState: {
data: {
website: "google.com",
visited: false,
count: 0
}
}
})
如果我想将 myState.data.visited 更改为 true,我该怎么办?
解决方案
您需要获取数据,对其进行更改并再次保存。
chrome.storage.local.get('storageKey', function(result) {
//data.visited will be in the result object for a specific key. You can change data.visited
//to be true here. After changing it to true you can save it again under
//the key 'storageKey' or any key you like.
chrome.storage.local.set({storageKey: result});
});
推荐阅读
- java - 如何根据用户的触摸移动图像?
- elasticsearch - 跨多个索引/过滤器的查询的function_score未按预期工作
- c# - relaxed Security AppiumService
- c - OpenMP 中的 threadprivate 错误
- php - FPDF 正确打印 NumberFormatter 类给出的货币符号
- c# - Json.net反序列化具有接口属性的复杂类
- chatbot - 聊天机器人的业务验证
- java - 除非明确指定,否则如何在默认情况下将 Spring Data JPA 从 camelCase 命名为 snake_case?
- jquery - 将边框的宽度设置为与文本宽度相同
- opencl - Do I need more events when timing multiple work-items?