我只是想像这样将数据导出到excel中
purchaseRequestService.prototype.export = function (arrID, arrID_A) {
var self = this;
var q = $q.defer();
var tasks = [];
if (arrID.length > 0) {
tasks.push(self.getDataForExportDashboard(arrID));
}
if (arrID_A.length > 0) {
tasks.push(self.getDataForExportDashboard_A(arrID_A));
}
//$q.all(tasks).then(function (res) {
// $q.all([self.getDataForExportDashboard(arrID),self.getDataForExportDashboard_A(arrID_A)]).then(function (res) {
$q.all([ self.getDataForExportDashboard(arrID), self.getDataForExportDashboard_A(arrID_A)]).then(function (res) {
var dt = [];
if (res.length > 1) {
dt.push(res[0][0].concat(res[1][0]));
dt.push(res[0][1].concat(res[1][1]));
} else {
dt.push(res[0][0]);
dt.push(res[0][1]);
}
var q = $q.defer();
ExcelService.exportDashboard(dt).then(function (result) {
q.resolve(result);
}, function (error, status) {
q.reject({
error: result,
status: status
});
});
});
return q.promise;
}
现在它的表现很奇怪,有时excel会被下载,有时候不会。当我打开调试工具并在断点处停止代码时,下载成功。我无法理解发生了什么。