2013-10-11 41 views
0

使用API​​ v1。在Spotify应用程序api中链接加载调用

不知道多频繁我不得不做这样的事情,但我怀疑一点点。

我想检查用户是否是播放列表的所有者。是否有可能没有下面的嵌套负载链接?我看到那Promises can be joined,但我不认为我可以加载currentUser未加载owner。任何方式来简化这个?

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); 
      } 
     }); 
    }); 
+0

从我所看到的,看起来这个嵌套是计划。类似。 – Thomas

回答

1

你说得对,你的是检查它的最好方法。你需要做2个异步调用并像那样链接它们。

另一种方法是首先获取该标识符用于通过models.session.user.load('username').done(function(u) { ... });当前用户,它返回的用户名,然后与播放列表的所有者(前缀的用户名与spotify:user:的URI进行了比较。但是,因为你可以看看,这个替代方案不会让你免于进行2个嵌套调用。

相关问题