16

我有 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;
  });

我本以为它们会用逗号分隔,但我想不是。

4

2 回答 2

20

Chrome Storage 文档中,它说:

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

最简单的方法是通过替换你的来传递一个{}数组[]

于 2015-03-24T02:10:45.743 回答
0

根据官方文档,它将如下所示。

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;
});
于 2020-10-22T05:05:39.603 回答