使用Framework7在Phonegap上上传文件的进度条

时间:2017-05-17 09:59:35

标签: jquery html5 cordova html-framework-7 phonegap

我正在尝试使用phonegap / cordova和Framework7将图像上传到服务器。我可以毫无问题地上传图片,但如何显示上传状态的进度条?

我的HTML:

function uploadPhoto(imageURI) {
 var options = new FileUploadOptions();
 options.fileKey = "file";
 options.fileName = imageURI.substr(imageURI.lastIndexOf('/') + 1);
 options.mimeType = "image/jpeg";
 console.log(options.fileName);
 var params = new Object();
 params.value1 = "test";
 params.value2 = "param";
 options.params = params;
 options.chunkedMode = false;

var ft = new FileTransfer();
 ft.upload(imageURI, "http://www.my-server.com/upload.php", function(result){
 console.log(JSON.stringify(result));
 }, function(error){
 console.log(JSON.stringify(error));
 }, options);

 // I have tried this to show progress but it doesn't work.
     $("#progressbar").show();
    ft.onprogress = function(progressEvent) {

    perc = Math.floor((progressEvent.loaded / progressEvent.total) * 100);

    $("#progressbar").progressbar({value:perc});

    }
 }

使用Javascript / JQuery的

{{1}}

1 个答案:

答案 0 :(得分:0)

来自framework7 docs:

var progressbar = $$('#progressbar');
myApp.setProgressbar(progressbar, prec);

有关其他选项,请参阅Progressbar framework7