通过使用此函数,我尝试将几个对象添加到临时数组。
var temp = [];
function addSong(id) {
var button = $('#' + id + ''); // Button that triggered the modal
var file = button.data('file'); // Extract info from data-* attributes
var thumb = button.data('thumb'); // Extract info from data-* attributes
var trackName = button.data('track_name'); // Extract info from data-* attributes
var trackArtist = button.data('track_artist'); // Extract info from data-* attributes
var trackAlbum = button.data('track_album'); // Extract info from data-* attributes
temp += "{file:'" + file + "',thumb:'" + thumb + "',trackName:'" +
trackName + "',trackArtist:'" + trackArtist + "',trackAlbum:'" + trackAlbum + "'},";
$("#player").jAudio({
playlist: []
});
}

答案 0 :(得分:0)
您需要传递一个对象数组而不是字符串。如下面的示例
Application.onCreate()
所以将你的临时变量改为
$("#player").jAudio({
playlist: [{
file: "resources/tracks/01.mp3",
thumb: "resources/thumbs/01.jpg",
trackName: "Track 1",
trackArtist: "Artist 1",
trackAlbum: "Album",
}, {
file: "resources/tracks/02.mp3",
thumb: "resources/thumbs/02.jpg",
trackName: "Track 2",
trackArtist: "Artist 2",
trackAlbum: "Album",
}]
});
然后在数组中使用它
var temp = {
file: file,
thumb: thumb,
trackName: trackName,
trackArtist: trackArtist,
trackAlbum: trackAlbum
};
根据更新后的问题,您可以将js函数修改为类似
的内容 $("#player").jAudio({
playlist: [temp]
});