Я хочу сделать цикл в данном Java-скрипт, чтобы динамически извлекать данные из папки, как песни,ява скрипт зацикливание для динамических данных
<script type="text/javascript">
Amplitude.init({
"songs": [
{
"name": "Living Proof",
"artist": "Gregory Alan Isakov",
"album": "The Weatherman",
"url": "HH.mp3",
"live": false,
"cover_art_url": "images/theweatherman.jpg"
},
],
"default_album_art": "images/no-cover-large.png",
"callbacks": {
"after_init": "album_change",
"after_album_change": "album_change",
"after_song_ended": "album_change"
}
});
function album_change(){
var activeSong = Amplitude.getActiveSongMetadata();
$('.album-display').hide();
$('.album-container').removeClass('active-album-container');
switch(activeSong.album){
case 'The Weatherman':
$('.the-weatherman-display').show();
$('.the-weatherman').addClass('active-album-container');
break;
case 'Rooms For Adelaide':
$('.rooms-for-adelaide-display').show();
$('.rooms-for-adelaide').addClass('active-album-container');
break;
case 'The Suburbs':
$('.the-suburbs-display').show();
$('.the-suburbs').addClass('active-album-container');
break;
}
}
$('.album-container').click(function(){
$('.album-display').hide();
$('.album-container').removeClass('active-album-container');
if($(this).hasClass('the-weatherman')){
$('.the-weatherman-display').show();
$('.the-weatherman').addClass('active-album-container');
}
if($(this).hasClass('rooms-for-adelaide')){
$('.rooms-for-adelaide-display').show();
$('.rooms-for-adelaide').addClass('active-album-container');
}
if($(this).hasClass('the-suburbs')){
$('.the-suburbs-display').show();
$('.the-suburbs').addClass('active-album-container');
}
});
</script>
Пока ваши выборки данных является массив объектов, вы можете использовать 'Array.prototype.map' и' Array.prototype.filter', чтобы извлечь нужные данные. – evolutionxbox
В чем вопрос? Сначала отредактируйте его, потому что форматирование повсюду. Тогда задайте точный вопрос. Если вы спрашиваете, как сделать цикл в javascript, вы можете сначала попробовать Google. – Charleshaa