【发布时间】:2014-12-24 12:26:10
【问题描述】:
这是为了访问保存在 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: object is not a function 在 HTMLDocument.restore_options
而且错误指向第一行 (chrome.storage.sync.get('allWeights')。
是什么导致了这个错误,我该如何解决?
【问题讨论】:
-
还有
chrome.storage.sync.set发生吗? -
是的,设置是在“save_options()”函数中进行的,保存时没有错误/错误/问题
-
是的,但我相信问题就在那里。也就是说,代码
chrome.storage.sync.get('allWeights')正在返回一个未定义\空对象。这意味着在'allWeights'上使用get是问题所在。这应该追溯到set。你能编辑并提供集合吗?还是链接? -
因为代码在 S.O. cmets很难阅读,这里是GitHub链接:github.com/dsouzarc/powerSchoolGradeCalculator/blob/master/…我将数据设置在第140行
-
如果您有任何问题,请告诉我
标签: javascript google-chrome google-chrome-extension google-chrome-devtools google-chrome-app