首先,如果我没有确定正确的数组类型,请原谅我,但我似乎无法弄清楚这一点。
我正在尝试在查询中运行此数组:
var myArray = {"artists":[{
"a1":"Adam Sandler",
"a2":"Adam Lambert",
"a3":"Avril Levine",
"a4":"Backstreet Boys",
"a5":"Blackstreet",
"a6":"Black Eye Peas",
"a7":"Cool and the Gang",
"a8":"Chicago",
"a9":"Charlie Manson"
}],
"songs":[{
"s1":"Grow Old With You",
"s2":"Whatdaya Want From Me",
"s3":"Yea yea",
"s4":"Quit Playing Games With My Heart",
"s5":"No Digity",
"s6":"Meet Me Half way",
"s7":"Doo wa ditty",
"s8":"Fight for your honor",
"s9":"Charlies Song"
}],
"genre":[{
"g1":"Pop",
"g2":"Pop",
"g3":"Alternative",
"g4":"R & B",
"g5":"R & B",
"g6":"Hip-Hop",
"g7":"Funk",
"g8":"Soft Rock",
"g9":"Rock"
}]};
当我单击一个按钮(比如标题)时,我不知道如何让它自动通过数组。这就是我的按钮:
$.each(myArray.songs, function(e,i){
console.log("e:"+e+" - i:"+i+" - "+myArray.songs[e].i);
});
这确实有效,但是当它到达 console.log 时,这就是我得到的:
e:0 - i:[object Object] - 未定义
我不知道如何让“i”工作,它总是给我 [Object Object]。我将 I 替换为数组中的实际 id,它可以工作。
谢谢你。