我使用传递给函数的数组来存储 getJSON 结果中的数据,但是,它总是什么都不返回。无论如何将getJSON返回的数据存储到数组中?getHashImages(tagVals[0], 5, imagesToParse);
function getHashImages(tag, count, result) {
// Clear all images
$('ul.images').html('');
var url = 'https://api.instagram.com/v1/tags/'+tag+'/media/recent?&client_id=5a7b13571ced47418dd539e6fc97a67f&count='+count+'&callback=?';
document.writeln('In function the length of ' + result.length + '<br />');
$.getJSON(url, function(data) {
console.log(data.data.length);
if(data.data.length === 0){
// $('ul.images').append('<li>No results</li>');
} else {
$.each(data.data, function(index, value){
//console.log(value);
var imgUrl = value.images.low_resolution.url,
imgUser = value.user.username,
imgLink = value.link;
result.push(imgLink);
document.writeln('In function the length of ' + result.length + 'after JSON <br />');
//$('ul.images').append('<li><a href="'+imgLink+'" target="_blank"><img src="'+imgUrl+'"/></a></li>');
});
}
});
document.writeln('In function the length of ' + result.length + 'after JSON <br />');
}