2013-10-11 45 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個嵌套調用。

相關問題