2013-10-11 3 views
0

API v1 사용.Spotify 앱에서로드 불러 오기 api

얼마나 자주 이런 일을해야할지 모르지만, 나는 공정한 생각이 듭니다.

사용자가 삭제 된 재생 목록의 소유자인지 확인하고 싶습니다. 아래에 중첩 된로드 체인없이이 작업을 수행 할 수 있습니까? 나는 그 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); 
      } 
     }); 
    }); 
+0

이 중첩이 계획 인 것처럼 보입니다. load ('owner.currentUser') 또는 뭔가를 말할 수 있기를 바랍니다. 비슷한. – Thomas

답변

1

네가 옳았는데 네가 그걸 확인하는 가장 좋은 방법이야. 2 개의 비동기 호출을 만들어이를 체인화해야합니다.

다른 방법으로는 사용자 이름을 반환하는 models.session.user.load('username').done(function(u) { ... });을 통해 현재 사용자의 식별자를 가져온 다음 재생 목록 소유자의 URI와 비교합니다 (사용자 이름 앞에 spotify:user: 접두사를 붙이면됩니다. 이 대안은 두 중첩 된 호출을하지 못하게합니다.