目前我在我的网站www.midnightlisteners.com上集成了Last.fm API,但它将所有Last.fm数据放在最后一个Kanye West上。如果您将鼠标悬停在(i)图标上,您将看到数据出现在工具提示中。Last.fm API jQuery
我想遍历所有并将它们添加到相应的位置。如果有人能够帮助我获得小艺术家的形象,那么这将是非常棒的。
我的jQuery代码:
$(document).ready(function() {
// Find Related Artists based on Last.fm JSON Results
$(".artist-data").each(function() {
// Find the artist name in the "p" tag and save it
artistName = $(this).find(".artist-wrap-mid p");
artist = artistName.text();
// Create a class out of the artist name made of lowercase letters and "-" instead of spaces
artistClass = artist.toLowerCase().replace(/ /g, '-');
// Add this class to the .artist-data div
$(this).addClass(artistClass);
// Check if a value is present
if (artist === '') {
$("." + artistClass + " .related").html("No related artist info found for " + artist);
}
// Otherwise return the request with links to each related artist
else {
$.getJSON("http://ws.audioscrobbler.com/2.0/?method=artist.getsimilar&artist=" + artist + "&api_key=9c991c10bf461ac4e4f92fdfa14c20c2&limit=3&format=json&callback=?", function(data) {
var html = '';
$.each(data.similarartists.artist, function(i, item) {
html += "<a href='http://" + item.url + "' target='_blank'>" + item.name + "</a>, ";
}); // End each
$("." + artistClass + " .related").append(html);
}); // End getJSON
} // End Else
});
});
我的HTML,最好在我的网站上看到:www.midnightlisteners.com
但它把所有的数据从Last.fm中<div class="related"> </div>
我已经获得了吨的帮助在这里:writing.sackettsolutions.com/2012/02/navigating-the-last-fm-api-with-a-little-help-from-jquery-getjson
感谢的线,你能不能帮也许我这?我对jQuery非常陌生。我刚开始阅读jQuery新手忍者书:D – Pullapooh
见编辑上面... – devnull69
我将如何实现这个在我的代码? – Pullapooh