我将 blob 对象存储在 chrome.storage.local 中,并增加键“0”、“1”、“2”等。对象的数量不固定。从“0”开始迭代读取和处理它们的最佳方法是什么? (在前一个对象未被处理之前,我无法读取下一个对象)。
我知道可以使用此代码获取所有对象:
chrome.storage.local.get(null, function(items) {
//handle items
});
但就我而言,可能有很多 blob 文件,我不想一次在内存中处理它们。
最佳答案
所以你只需要一个简单的循环,当你完成时,它会加载网络项目。简单队列类型的系统。
(function() {
var ind = 0;
function getNextItem() {
var data = chrome.storage.local.get("key" + ind, processItem);
ind++;
}
function processItems(items) {
if(!items) return;
//do stuff here when done call next
getNextItem(); // call this whenever your processing is done
}
getNextItem();
}());
关于javascript - 迭代地读取和处理 chrome.storage 中的对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41122060/