`

列表下载

阅读更多

 这段代码比较巧妙的是 window.Fileindex 变量,这里用到appcan api

 

var inOpCode = 1;
 window.Fileindex = -1;    

 function DownloadNext(i) {
  window.Fileindex=window.Fileindex+1;
  if(window.Fileindex<$("#list li").length){
   inOpCode = $("#list li:eq("+window.Fileindex+")").attr("fileid");//取得Li列表中第fileindex的fileID
   uexDownloaderMgr.createDownloader(inOpCode);//调用appcan api
  }
 }

 window.uexOnload = function() {
  uexDownloaderMgr.onStatus = function(opCode, fileSize, percent, status) {
   switch (status) {
   case 0:$("#list li[fileid=" + opCode+"]").find(".downloadState").text(percent + "%");
    break;
   case 1:
    $("#list li[fileid=" + opCode+"]").find(".downloadState").text("完成");
    uexDownloaderMgr.closeDownloader(opCode);
    DownloadNext(window.Fileindex);//完成一个之后接着继续下一个下载
    break;
   case 2:
    $("#list li[fileid=" + opCode+"]").find(".downloadState").text("失败");
    uexDownloaderMgr.closeDownloader(opCode);
    DownloadNext(window.Fileindex);
    break;
   }
  };
  
  uexDownloaderMgr.cbCreateDownloader = function(opCode, dataType, data) {
   if (data == 0) {
    $("#list li[fileid=" + opCode+"]").find(".downloadState").text("正在下载");
    var url = $("#list li[fileid=" + opCode+"]").attr("fileurl");
    var savepath = "wgt://data/"+url.split("/")[url.split("/").length-1];
    uexDownloaderMgr.download(inOpCode, url,savepath,'1');
   }else{
   }
  };
 };

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics