我有一个
PHP在目录中创建一个mp3文件的JSON数组. PHP的JSON数组输出是:
[{"title":"Kalimba","mp3":"/path/to/mydirectory/Kalimba.mp3"},{"title":"Maid with the Flaxen Hair","mp3":"/path/to/mydirectory/Maid with the Flaxen Hair.mp3"},{"title":"Sleep Away","mp3":"/path/to/mydirectory/Sleep Away.mp3"}]
很好,它似乎是JQuery.jPlayer所期望的.
现在在一个基本的jplayer.js文件中,我有:
$(document).ready(function(){ new jPlayerPlaylist({ jPlayer: "#jquery_jplayer_1",cssSelectorAncestor: "#jp_container_1" },[ //I guess my JSON array should come here // but no idea on how I put it in... ],{ swfPath: "../js",supplied: "mp3",wmode: "window" }); });
我的问题是我不能把我的JSON数组放在它应该的位置(参见js代码中的注释)
任何帮助将非常感谢!
原谅我的英语,这不是我的母语
提前致谢
编辑&解决了
大家好,
对于那些有兴趣的人,我找到了解决方案:
我的JS文件是:
$(document).ready(function(){ var cssSelector = { jPlayer: "#jquery_jplayer_1",cssSelectorAncestor: "#jp_container_1" }; var playlist = []; // Empty playlist var options = { swfPath: "./js",supplied: "mp3" }; var myPlaylist = new jPlayerPlaylist(cssSelector,playlist,options); $.getJSON("../PHP/radio.PHP",function(data){ // get the JSON array produced by my PHP $.each(data,function(index,value){ myPlaylist.add(value); // add each element in data in myPlaylist }) }); });