【发布时间】:2016-11-20 02:43:06
【问题描述】:
变量 ntabs 到底是空的,我如何更改此代码(可能使用 Q 或异步库)以使其正常工作
var actions = [..];//array of objects
var ntabs = [];//arr where i put results
actions.forEach(function(a) {
chrome.tabs.query({url: a.url}, function(tabs) {
tabs.forEach(function(tab) {
var t = {
id: tab.id,
title: tab.title,
url: tab.url,
faviconUrl: tab.favIconUrl,
actions: a.actions
}
ntabs.push(t);
});
});
});
console.log(ntabs);//result is empty
【问题讨论】:
标签: javascript asynchronous google-chrome-extension q async.js