To fill the album names, we will iterate in the response JSON and create HTML with album names. We will then place this HTML inside the placeholder in the left panel:
Write this code for method
fillAlbumNames
to display albums in the left panel:var albumNames = []; $.each(this.jsonAlbums, function(key, album) { albumNames.push('<h4 class="ui-widget-header album" data-id="' + album.id + '">' + album.albumName + ' </h4>'); }); $('#albumNames').html(albumNames.join(''));
We have declared an array
albumNames
that will hold the DOM structure for each album.Next we iterate in
jsonAlbums
property using jQuery's$.each
iterator. In each iteration we create anh4
element with the album name inside it.We also attach CSS classes
ui-widget-header
andalbum
to it, and a data attributedata-id
, which is set to theid
of thealbum
, has also been added.After
$.each
is finished, we push the DOM inside the divalbumNames
.