Note that there are some explanatory texts on larger screens.

plurals
  1. POSpotify Clear Playlist Drag and Drop
    primarykey
    data
    text
    <p>When you drag/drop an Artist into my app in the sidebar, I build a temporary playlist. Every time I drag a new Artist into my app, it builds a new list after the previous, WITHOUT clearing out the old one. (Note there is some code missing from here that is probably not needed).</p> <p>My question: how do I clear out or remove the current built playlist THEN build a new one, every time I drag/drop an Artist into my app? I suspect it would need to be called inside getRelated()?</p> <pre><code> models.application.addEventListener('dropped', sidebarDropEventListener); function sidebarDropEventListener() { for(var i = 0; i &lt; models.application.dropped.length; i++){ var draggedItem = models.application.dropped[i]; updateFromDragged(draggedItem.uri); } } function updateFromDragged(droppedUri) { // If dropped item is an artist if(droppedUri.indexOf('artist') &gt;= 0) { getRelated(droppedUri); } else { console.warn('Dropped item is not an artist'); } } // Build playlist function buildList(trackURIArray){ var arr = trackURIArray; models.Playlist .createTemporary("myTempList_" + new Date().getTime()) .done(function (playlist){ playlist.load("tracks").done(function() { playlist.tracks.add.apply(playlist.tracks, arr).done(function(){ // Create list var list = List.forCollection(playlist); // Populate DOM $('#playlistContainer').append(list.node); list.init(); }); }); }); } // Get Related function getRelated(artist_uri){ models.Artist .fromURI(artist_uri) .load('related','name') .done(function (artist){ artist.related.snapshot().done(function (snapshot){ snapshot.loadAll().done(function (artists){ var promises = []; for(var i = 0; i &lt; artists.length; i++){ var promise = getTopTrack(artists[i], 1); promises.push(promise); } models.Promise.join(promises) .done(function (tracks){ buildList(tracks); }) .fail(function (tracks){ buildList(tracks); }); }); }); }); } </code></pre>
    singulars
    1. This table or related slice is empty.
    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.
    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