English 中文(简体)
2. 制作一个有多种选择的系列节目,以播放音乐剧。
原标题:Make an array with multiple options for music playlist

我试图利用标签制作一个超文本5的游戏清单。 我想把所有歌曲、其名称、描述等等放在一个阵列中。 我不知道如何很好地使用阵列。

我现在想的是:

var songBase =  /songs/ 
var playlist = {};
playlist = {
                         Bleeding Love              :    Bleeding_love.mp3 ,
                         Don t Forget              :    Dont_forget.mp3 ,
                         Finish                     :    Finish.mp3 ,
                         In the Rain                :    In_the_rain.mp3 ,
                         Ready to Fall              :    Ready_to_fall.mp3 ,
                         Realize                    :    Realize.mp3 ,
                         Righted All Your Wrongs    :    Righted_all_your_wrongs.mp3 ,
                         These Walls                :    These_walls.mp3 
                    }

我确实需要做的是两个以上选择。 我也不知道如何从我已经掌握的阵列中提取任何数据。

任何想法?

最佳回答

在技术上,你使用了字面字面({})而不是阵列([...])。

You can use an array of objects literals for your purposes.

var playlist = [
  {
    name: "Bleeding Love",
    file_name: "Bleeding_love.mp3"
  },
  {
    name: "Don t Forget",
    file_name: "Dont_forget.mp3"
  }
]

那么,你可以接触到这样的情况:

playlist[1].file_name

或者在 lo中:

for (var i=0; i<playlist.length; i++) {   # i is array index
  for (var k in playlist[i]) {            # k is the key
    console.log(k+ :  +playlist[i][k]);
  }
}
问题回答

暂无回答




相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签