// variables to be used throughout
var videos = new Array();
// similar artist/bands
function similarTo(who) {
$.getJSON('http://ws.audioscrobbler.com/2.0/?method=artist.getsimilar&artist='+who+'&limit=20&api_key=b25b959554ed76058ac220b7b2e0a026&format=json&callback=?', function(data) {
$.each(data , function(i,similars) {
$.each(similars.artist, function(c, artist) {
$.getJSON('http://gdata.youtube.com/feeds/api/videos?q='+artist.name+'&orderby=relevance&start-index=1&max-results=1&v=2&alt=json-in-script&callback=?', function(data) {
$.each(data.feed.entry, function(i,video) {
videos.push({
id: video.id.$t.split(":")[3],
title: video.title.$t
});
});
});
});
initPlaylist();
});
});
}
// start the playlist
function initPlaylist() {
$('#ytplayerid').load('includes/ytplayer.php?track=' + videos[currenttrack].id);
$('#player span').html(videos[currenttrack].title);
}
後,當我的代碼到達initPlaylist()
功能的視頻陣列顯示爲空,我有一種感覺自己居然被解僱之前$.getJSON()
來電顯示爲空... 這可能嗎?如果我在每個push()
之後添加一個console.log(視頻),該陣列實際上正在構建。爲什麼我的數組調用函數時,該陣列是內置的JS
我認爲這是一個範圍的問題。視頻被定義在哪裏? – thedaian 2011-05-25 15:33:21