我试图在一个抽搐通道阵列中为每个通道进行两次json调用。由于某种原因,在第二次json调用中未定义数组项。
var streamers = ["freecodecamp", "medrybw", "brunofin", "storbeck", "terakilobyte", "habathcx", "RobotCaleb", "thomasballinger", "noobs2ninjas", "beohoff"],
streamerList = $('ul.list-group');
for (var i = 0; i < streamers.length; i++) {
$.getJSON("https://api.twitch.tv/kraken/streams/" + streamers[i], function(streamData) {
$.getJSON("https://api.twitch.tv/kraken/channels/" + streamers[i] //undefined, function(channelData) {
var listItem = $('<li/>').addClass('list-group-item').appendTo(streamerList);
var nameLink = $('<a/>').html(JSON.stringify(channelData.display_name)).appendTo(listItem);
});
});
}