I have returned an object from an API call to Last.FM that returns an object of the last 100 songs I listened to. If one is currently playing there is a nowplaying flag on the first item in the object.
I'm trying to bind a class to the markup if this is the case, and I'm close. The only problem is if the condition is met it's instead binding the class to everything iterated from my object.
What have I done wrong?
To understand here is an example snippet from the returned object
{
"artist": {
"mbid": "9457a08d-a2d0-4f2d-9876-b8870612d54f",
"#text": "The Last Poets"
},
"@attr": {
"nowplaying": "true"
},
"mbid": "3066a862-6c9a-4e21-b6bd-53e43257cbb4",
"album": {
"mbid": "96e8dd6c-6b49-462e-a6ea-202a3e2b1116",
"#text": "Understand What Black Is"
},
"streamable": "0",
"url": "https:\/\/www.last.fm\/music\/The+Last+Poets\/_\/Understand+What+Black+Is",
"name": "Understand What Black Is"
},
{
"artist": {
"mbid": "77b29df2-056e-409e-a1b2-5e2bbfe421c4",
"#text": "Awolnation"
},
"album": {
"mbid": "1f7c0747-0207-441d-acad-a55ec0530b1f",
"#text": "Back From Earth"
},
"streamable": "0",
"date": {
"uts": "1560027115",
"#text": "08 Jun 2019, 20:51"
},
"url": "https:\/\/www.last.fm\/music\/Awolnation\/_\/Sail",
"name": "Sail",
"mbid": "0960742a-7040-435e-a2ef-c11abec3b913"
}
and in the markup i have iterated over my object like this
<li v-for="(track, index) in recentTracks" :key="`track-${index}`" class="track" v-bind:class="'track-' + index" style="background-image: url('http://www.placecage.com/100/100')">
<span v-bind:class="{ 'playing': 'track.@attr.nowplaying' }">{{track.artist['#text']}} - {{track.name}}</span>
</li>
</ul>
Which results in every li
having the class of playing