我正在使用PhoneGap(Cordova)文件传输和onProgress功能向用户显示下载进度。
到目前为止它工作得很好,但是我试图同时进行多次下载,并且我需要在onProgress事件中拥有一个有效的“target”属性,但它总是读为null。
为什么?有没有办法让它显示目标,就像它提供的文件名称一样?
var ft0 = new FileTransfer();
ft0.onprogress = onProgress;
ft0.download( url, filePath, onDownloadSuccess, onDownloadError );
function onProgress(progressEvent) {
....
这是onProgress事件的属性读数
type: undefined;
bubbles: false;
cancelBubble: false;
cancelable: false;
lengthComputable: true;
loaded: 5510;
total: 56456;
target: null;
非常感谢任何帮助。
感谢。
答案 0 :(得分:1)
由W3C spec定义的进度事件没有目标。
您可以将下载操作包含在一个闭包中,并且可以访问文件名,如下所示:
filePaths.each(function(filePath) {
var ft = new FileTransfer();
ft.onprogress = function(progressEvent) {
//onProgress for filePath
};
button.addEventListener("click", function() {
ft.abort();
}, false);
ft.download( url, filePath, onDownloadSuccess, onDownloadError );
});