Note that there are some explanatory texts on larger screens.

plurals
  1. POSpotify API Create Temp Playlist Not Loading
    primarykey
    data
    text
    <p>I'm making a little app that displays a list of the top first song of an artist's related artists. When I try and load my app for the first time, it shows nothing. But, when I "Reload Application" everything seems to work. When I constantly start "Reloading" it keeps adding more of the same tracks to the list as well. </p> <p>How do I stop it from continually appending more tracks to the list as well as tighten up the code so that it works on load?</p> <pre><code>require([ '$api/models', '$views/list#List', '$api/toplists#Toplist' ], function(models, List, Toplist){ 'use strict'; // Build playlist function buildList(trackURIArray){ var arr = trackURIArray; models.Playlist .createTemporary("myTempList") .done(function(playlist){ playlist.load("tracks").done(function(loadedPlaylist){ for(var i = 0; i &lt; arr.length; i++){ loadedPlaylist.tracks.add(models.Track.fromURI(arr[i])); } }); // Create list var list = List.forPlaylist(playlist,{ style:'rounded' }); $('#playlistContainer').append(list.node); list.init(); }); } // Get top track function getTopTrack(artist, num, callback){ var artistTopList = Toplist.forArtist(artist); artistTopList.tracks.snapshot(0, num).done(function (snapshot){ snapshot.loadAll('name').done(function(tracks){ var i, num_toptracks; num_toptracks = num; for(i = 0; i &lt; num_toptracks; i++){ callback(artist, tracks[i]); } }); }); } // Get Related function getRelated(artist_uri){ var artist_properties = ['name', 'popularity', 'related', 'uri']; models.Artist .fromURI(artist_uri) .load(artist_properties) .done(function (artist){ artist.related.snapshot().done(function(snapshot){ snapshot.loadAll('name').done(function(artists){ var temp = []; for(var i = 0; i &lt; artists.length; i++){ getTopTrack(artists[i], 1, function(artist, toptrack){ var p, n, u; p = artist.popularity; n = artist.name; u = artist.uri; temp.push(toptrack.uri); }); } // Build a list of these tracks buildList(temp); }); }); }); } getRelated('spotify:artist:2VAvhf61GgLYmC6C8anyX1'); }); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload