1

在直接中,我想删除上传器中的文件,我这样做了

 $scope.close = function() {
        console.log($scope);
        $scope.isOpen = false;
        $('.file_container').empty();
        **angular.forEach($scope.uploader.files, function(v, k) {
            $scope.uploader.removeFile(v);
            $scope.fileLength = $scope.uploader.files.length;
        });**

    };

    $scope.uploader = new plupload.Uploader({
        runtimes: 'html5,html4',
        browse_button: 'addFile',
        max_file_size: '20000mb',
        chunk_size: '512kb',
        // resize: { width: 125, height: 85, quality: 90 },
        flash_swf_url: '../scripts/lib/plupload.flash.swf',
        filters: [{
                extensions: 'jpg,png'
            }]
    });

    $scope.fileLength = 0;
    $scope.currentUpload = 0;
    $scope.uploader.bind('init', function() {
        console.log('init');
    });
    $scope.uploader.bind('UploadProgress', function(up, files) {
        $('.progress_percent').eq($scope.currentUpload).html(files.percent + '%');
        $('.progress_bar').eq($scope.currentUpload).css('width', files.percent + '%');
    });
    $scope.uploader.bind('FilesAdded', function(up, files) {
        $scope.$apply(function() {
            $scope.fileLength = files.length;
        });
        console.log($('input[type=file]'));
        readURL($('input[type=file]')[0]);
    //    up.start();
    });
    $scope.uploader.bind('BeforeUpload', function(up, file) {
        var mediaName = 'MediaBank' + Math.random().toString().substr(2);
        up.settings.url = '/Upload.ashx?medianame=' + mediaName + '&activityid=2013';
    });
    $scope.uploader.bind('FileUploaded', function(up, file, info) {
        $scope.currentUpload++;
        console.log($scope.currentUpload);
    });
    $scope.uploader.init();
    $('#save').bind('click', function() {
        $scope.uploader.start();
    });

而且,当我添加 2 个文件时,当调用“$scope.close”函数时,只删除了 1 个文件……为什么?谢谢大家 !

4

1 回答 1

1

可能是迭代器的问题,并且您在浏览列表时正在更改列表。

您可以尝试更换:

**angular.forEach($scope.uploader.files, function(v, k) {
            $scope.uploader.removeFile(v);
            $scope.fileLength = $scope.uploader.files.length;
        });**

和 :

$scope.uploader.splice(0); // $scope.uploader.splice(); should work too
$scope.fileLength = $scope.uploader.files.length;

希望这会有所帮助

于 2013-09-10T07:58:59.903 回答