How can I let a user download multiple files when a button is clicked?

前端 未结 9 1072
不知归路
不知归路 2020-11-27 18:18

So I have a httpd server running which has links to a bunch of files. Lets say the user selects three files from a file list to download and they\'re located at:

         


        
9条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-27 18:47

        
        
            
                
                
                
                
            
                    
                
    Select File name Downloads
    {{tableData.fileName}} download
    download selected

    {{selectedone}}

    app.js var app = angular.module('app', []); app.controller('FirstCtrl', ['$scope','$http', '$filter', function($scope, $http, $filter){ $scope.tableDatas = [ {name: 'value1', fileName:'file1', filePath: 'data/file1.txt', selected: true}, {name: 'value2', fileName:'file2', filePath: 'data/file2.txt', selected: true}, {name: 'value3', fileName:'file3', filePath: 'data/file3.txt', selected: false}, {name: 'value4', fileName:'file4', filePath: 'data/file4.txt', selected: true}, {name: 'value5', fileName:'file5', filePath: 'data/file5.txt', selected: true}, {name: 'value6', fileName:'file6', filePath: 'data/file6.txt', selected: false}, ]; $scope.application = []; $scope.selected = function() { $scope.application = $filter('filter')($scope.tableDatas, { checked: true }); } $scope.downloadAll = function(){ $scope.selectedone = []; angular.forEach($scope.application,function(val){ $scope.selectedone.push(val.name); $scope.id = val.name; angular.element('#'+val.name).closest('tr').find('.downloadable')[0].click(); }); } }]);

    plunker example: https://plnkr.co/edit/XynXRS7c742JPfCA3IpE?p=preview

提交回复
热议问题