soo在桌面上做console.log工作,但是當我嘗試獲取單個值時,它返回undefined像這樣[undefined:「text」],第二個for循環變量總是5出於某種原因。我不知道如何重現這一點。 groupCache和shoutCache是空數組數組中的字符串僅在嘗試獲取單個值時返回undefined?
//userid, groupCache, shoutCache defined above
function arraysEqual(arr1, arr2) {
if(arr1.length !== arr2.length)
return false;
for(i = arr1.length; i--;) {
if(!arr2.indexOf(arr1[i]))
return false;
}
return true;
}
setInterval(function() {
$.getJSON("https://api.roblox.com/users/" + userid + "/groups").done(function (data) {
console.log(data)
for (i = 0; i < data.length; i++) {
if (!arraysEqual(data, groupCache)) {
groupCache.push(data[i].Id.toString())
}
}
for (var v = 0; v < groupCache.length; v++) {
$.get("https://web.roblox.com/My/Groups.aspx?gid=" + groupCache[v]).done(function (dataA) {
var elems = $(dataA);
var finda = $('#ctl00_cphRoblox_GroupStatusPane_StatusTextField', elems);
shoutCache[groupCache[v]] = finda.text() // does not work
console.log(groupCache[v] + " :GC")
console.log(shoutCache)
})
}
})
}, 10000);
的manifest.json
{
"manifest_version": 2,
"background": {
"scripts": ["/libs/jquery-3.2.1.min.js", "/scripts/Notify.js"]
},
"name": "Extension",
"browser_action": {
"default_title": "Extension"
},
"web_accessible_resources": [
"options.html",
"img/*.png",
"JSON/*.json"
],
"options_ui": {
"page": "options.html",
"chrome_style": true
},
"permissions": ["storage", "background"],
"short_name": "Extension",
"version": "0.1.0"
}
異步調用在for循環? –
是........... – Filip
? ............. – Filip