【发布时间】:2013-10-19 19:54:07
【问题描述】:
使用 API v1。
不确定我必须多久做一次这样的事情,但我怀疑有一点。
我想检查用户是否是已删除播放列表的所有者。如果没有下面的嵌套负载链,是否可以做到这一点?我看到了Promises can be joined,但我认为如果没有加载owner,我就无法加载currentUser。有什么办法可以简化吗?
var drop = models.Playlist.fromURI(...);
var success_message = document.createElement('p');
success_message.innerHTML = 'Playlist successfully dropped: ' + drop.uri;
this.appendChild(success_message);
drop.load('owner').done(function (playlist) {
playlist.owner.load('currentUser').done(function (owner) {
if (owner.currentUser) {
var allowed_message = document.createElement('p');
allowed_message.innerHTML = 'You are the owner of this playlist, let\'s get to work!';
drop_box.appendChild(allowed_message);
}
else {
var disallowed_message = document.createElement('p');
disallowed_message.innerHTML = 'You are not the owner of this playlist, choose a different one please!';
drop_box.appendChild(disallowed_message);
}
});
});
【问题讨论】:
-
据我所知,这个嵌套似乎是计划。希望能够说 load('owner.currentUser') 或类似的东西。
标签: javascript api spotify promise spotify-app