downloadList格式为数组,如: [{pro_id:2,path:'widget://res/aaa.mp3'},{pro_id:5,path:'widget://res/bbb.mp3'},{pro_id:12,path:'widget://res/ccc.mp3'}]
function checkLocalUrl (id,url) { if(downloadList.length == 0){ return url; }else{ var returnUrl = url; $.each(downloadList, function(k, v) { if(v.pro_id == id){ returnUrl = v.path; // return; // 相当于continue return false; // 相当于break } }); return returnUrl; } };
调用方式
var playUrl = checkLocalUrl('12','/Uploads/ddd.mp3'); alert(playUrl);
注意,需要真正返回的逻辑,在$each循环的外面做