如何否定 chrome.storage.local 中的变量

卡提克·萨米亚克

我需要否定/切换 chrome.storage.local 中变量的布尔值,但它抛出一个错误:

var toggle = chrome.storage.local.get('toggle');
chrome.storage.local.set({ "toggle": !toggle }, function() {
console.log('Settings saved');
});

我尝试先获取变量,但它显示了一个错误:表单 get(string) 的调用与定义 get 不匹配(可选字符串或数组或对象键,函数回调)。任何帮助表示赞赏!

用户1693593

由于读取是异步的,我们需要使用回调(因此出现错误消息):

chrome.storage.local.get("toggle", function(data) {               // async callback
  // check for errors via runtime.lastError

  // update settings
  chrome.storage.local.set({"toggle": !data.toggle}, function() { // invert and set
    // check for errors via runtime.lastError
    // Notify that we saved.
    console.log('Settings saved');
  });      
})

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何删除 chrome.storage.local

从JavaScript中的chrome.storage.local中删除以字符串开头的变量

如何从单独的js文件中调用存储在chrome.storage中的变量值?

开发Chrome扩展程序时如何清除“ chrome.storage.local”缓存?

chrome.storage.local 写入密钥的问题

chrome.storage.local.get和set

window.localStorage与chrome.storage.local

Chrome.Storage.Local持久性

从chrome.storage.local获取原始值

使用chrome.storage.local.set存储数据的安全性如何

如何使用chrome.storage.local.get和XMLHttpRequest同步执行功能?

是否可以在开发人员工具中查看chrome.storage.local?

在包含chrome.storage.local中保存的对象数组的对象中检查密钥

Chrome.storage.local.get在内容脚本中不起作用

chrome.storage.local get返回“未定义”

为什么 chrome.storage.local.get 返回 undefined 的值?

用玩笑测试chrome.storage.local.set

无法使用chrome.storage.local.set保存集

使用 chrome.storage.local.set 时 JSON 对象损坏

如何在Chrome DevTools的“网络”标签中添加否定过滤器?

chrome.storage.sync.set变量键

chrome extension + reactjs中的chrome.storage.sync.get回调后如何调用内部函数?

chrome.storage.local。在chrome.runtime.reload()之后获取空-打包的应用

chrome扩展名:从本地存储切换到chrome.storage.local

Chrome 擴展開發:chrome.storage.local vs Indexeddb

如何自动清除chrome.storage

如何解决chrome.storage.sync?

如何使用chrome.storage扩展

如何从chrome.storage检索此值?