J
J
jackie chan2015-11-14 22:53:22
JavaScript
jackie chan, 2015-11-14 22:53:22

How to combine two JavaScript codes?

So, hello everyone, there is a very interesting question in the implementation of this function there is a list of audio question how to implement the function when you click on the plus sign so that the audio is added to the list of audio recordings of the user VK c73a82a3ce6646669ce4527ec9113c3a.PNG
I get the list of audio like this

function recommendate(){
    VK.Api.call('audio.getRecommendations', {count: '1000'}, function(r) {
      if(r.response) {
        $('#playlist').empty().append($.map(r.response, function(song){
          return '<li><a href="'+ song.url +'"><b>'+song.artist+'</b> - '+ song.title +'<span class="label">'+ song.aid +' - '+ song.owner_id+'</span></a></li>'
        }))
      }
    });
};

I add these codes to the user in VK audio according to the previously known aid and ownerid
function addaudio(){
VK.Api.call('audio.add', { audio_id: 161291628, owner_id: -9880494 }, function (data) {
  if (data.response) {
    console.log(data.response);
  		}
  });
};

But aid and owner are chordcoded, how can I take the values ​​from the script above?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
sanex3339, 2015-11-14
@sanex3339

Well, aid is contained in the song object, we shove it into the data attribute of li or a or the plus sign itself (in the example below).
On the onclick of the plus sign, we get its data-aid and call the addaudio(aid) function, passing the aid argument accordingly.
But about the id of the user to whom to add an entry to favorites, let others who are more versed in the issue answer.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question