0

所以我编写了一个函数来从 C# 控制器中提取数据。它被拉入一个 FormData 对象,然后转换为一个数组,该数组应该被分解为逗号分隔的值。

但是,当我下载 csv 时,这就是我得到的(截图):

http://postimg.org/image/wex20t1h3/

这是我的 Angularjs 控制器代码:

angular.module("umbraco")
.controller("ExportAllController", function ($scope, $http) {

    $scope.filedownload = {};
    $scope.exportAll = function () {
        var downloadUrl = " /umbraco/backoffice/api/ExportDictionaryAll/ExportAll";
        var fd = new FormData();

        fd.append('file', $scope.filedownload);

        $http.get(downloadUrl, fd)
        .success(function (fd) {
            // ok
            $scope.fd = fd.split(',');

            console.log($scope.fd);
            alasql('SELECT * INTO CSV("AllDictionaryItems.csv" ) FROM ?', [$scope.fd]);
        })
        .error(function () {
            // handle upload error
            alert("Download Unsuccessful!");
        });

    };
});
4

1 回答 1

0
angular.module("umbraco")
.controller("ExportAllController", function ($scope, $http) {

    $scope.filedownload = {};
    $scope.exportAll = function () {
        var downloadUrl = " /umbraco/backoffice/api/ExportDictionaryAll/ExportAll";
        var fd = new FormData();

        fd.append('file', $scope.filedownload);
        window.open(downloadUrl, "_blank");
        $http.get(downloadUrl, fd)
        .success(function (fd) {
            // ok
            alert("Download Successful!");
        })
        .error(function () {
            // handle upload error
            alert("Download Unsuccessful!");
        });

    };

    $scope.greetings = [{
        name: "Export All Dictionary Items to CSV",
       def: "Click the button below to export a CSV file with all current dictionary items."
    }]
});

我错过了一个window.open(downloadUrl, "_blank");

于 2016-04-25T09:00:01.820 回答