Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/390.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/google-chrome/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/apache-flex/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
TypeError:对象不是函数(JavaScript Chrome存储同步)_Javascript_Google Chrome_Google Chrome Extension_Google Chrome Devtools_Google Chrome App - Fatal编程技术网

TypeError:对象不是函数(JavaScript Chrome存储同步)

TypeError:对象不是函数(JavaScript Chrome存储同步),javascript,google-chrome,google-chrome-extension,google-chrome-devtools,google-chrome-app,Javascript,Google Chrome,Google Chrome Extension,Google Chrome Devtools,Google Chrome App,这是为了访问保存在chrome.storage.sync中的首选项,使用JavaScript进行chrome扩展 代码: chrome.storage.sync.get('allWeights', function(obj) { allWeights = obj.allWeights(); chrome.storage.sync.get('allIDs', function(obj2) { allIDs = obj2.all

这是为了访问保存在chrome.storage.sync中的首选项,使用JavaScript进行chrome扩展

代码:

chrome.storage.sync.get('allWeights', function(obj) {  
          allWeights = obj.allWeights();

          chrome.storage.sync.get('allIDs', function(obj2) { 
            allIDs = obj2.allIDs();
            alert("ALL WEIGHTS: " + allWeights);
            alert("ALL IDS: " + allIDs);
         });
    });
错误:

响应storage.get:TypeError:对象不是函数时出错 在HTMLDocument.restore\u选项中

错误指向第一行(chrome.storage.sync.get('allWeights')

导致此错误的原因是什么?如何修复此错误?

编辑:此操作有效

 chrome.storage.sync.get(null, function(items) {
        allWeights = items.allWeights;
        allIDs = items.allIDs;
        alert("ALL WEIGHTS: " + allWeights);
        alert("ALL IDS: " + allIDs);
    }); 
我必须将items.allWeights()更改为items.allWeights


显然,您无法使用()访问对象属性。

是否也有
chrome.storage.sync.set
发生?是的,设置发生在“save_options()”函数中,saving没有错误/问题是的,但我相信问题就在那里。也就是说,代码
chrome.storage.sync.get(“所有权重”)
正在返回一个未定义的\空对象。这意味着在
'allWeights'
上使用
get
是个问题。这应该追溯到
set
。您可以编辑并提供集合吗?或者链接吗?因为S.O.注释中的代码很难阅读,这里是GitHub链接:我在第140行设置了数据。如果您需要,请告诉我有什么问题吗