所以我编写了一个从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!");
});
};
});
答案 0 :(得分: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."
}]
});
I was missing a window.open(downloadUrl, "_blank");