从Chrome存储中获取多个项目?

Jam*_*mie 9 google-chrome-extension google-chrome-storage

我有4件我想要的东西,但我不确定如何分开钥匙.使用逗号会出错.以下是我的用法示例:

chrome.storage.sync.get({
    'customImage',
    'customColor',
    'customRandColor',
    'customRandImage'
  }, function(backgroundCheckedOptions) {
    document.getElementById('optionsCustomImage').checked = backgroundCheckedOptions.customImage;
    document.getElementById('optionsBackgroundColor').checked = backgroundCheckedOptions.customColor;
    document.getElementById('optionsRandomColor').checked = backgroundCheckedOptions.customRandColor;
    document.getElementById('optionsRandomImage').checked = backgroundCheckedOptions.customRandImage;
  });
Run Code Online (Sandbox Code Playgroud)

我原以为他们会用逗号分开,但我猜不是.

Zig*_*del 13

Chrome存储文档中可以看出:

StorageArea.get(字符串或字符串或对象键数组,函数回调)

最简单的是通过更换你传递一个数组{}[]

  • 对象形式对于给出默认值也很有用:`{key1:default1,key2:default2}` (6认同)