我正在尝试使用以下代码通过Spotify API创建临时播放列表:
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();
但我收到以下错误:
core.js:4 - Uncaught TypeError: Object #<Promise> has no method 'load'
知道我做错了什么吗?感谢。
答案 0 :(得分: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();
});