0

I'm trying to create a temporary playlist through Spotify API with this code:

var playlist = models.Playlist.createTemporary("My temporary playlist");
models.Playlist.createTemporary("My temporary playlist").load('tracks').done(function(playlist) {
    playlist.tracks.add(models.Track.fromURI("spotify:track:4VqPOruhp5EdPBeR92t6lQ"));
    playlist.tracks.add(models.Track.fromURI("spotify:track:5HF5PRNJ8KGtbzNPPc93tG"));
});

var list = List.forPlaylist(playlist);
document.getElementById('playlistContainer').appendChild(list.node);
list.init();

But I'm getting the following error:

core.js:4 - Uncaught TypeError: Object #<Promise> has no method 'load'

Any idea what I'm doing wrong? Thanks.

4

1 回答 1

3

我找到了解决方案,仍然不确定为什么会这样,而我以前的代码没有,但是你去:

models.Playlist.createTemporary(playlist_name).done(function(playlist) {
  playlist.load('tracks').done(function(loadedPlaylist) {
    loadedPlaylist.tracks.add(models.Track.fromURI("spotify:track:4VqPOruhp5EdPBeR92t6lQ"));
    loadedPlaylist.tracks.add(models.Track.fromURI("spotify:track:5HF5PRNJ8KGtbzNPPc93tG"));
  });

  var list = List.forPlaylist(playlist);
  document.getElementById('playlistContainer').appendChild(list.node);
  list.init();
});
于 2013-08-21T16:46:03.327 回答