我是angularJS的新手。我想下载JSON文件。它正在使用chrome但不在Edge和Safari中。在safari文件中仅在浏览器中打开。 谢谢阅读。 Plz回复。
function itemExport() {
var a = document.createElement("a");
document.body.appendChild(a);
//a.style = "display: none";
if ($scope.selectedRows.length > 0) {
commonFactory.itemExport($scope.selectedRows, $scope.className).then(function (data) {
var json = JSON.stringify(data.data),
blob = new Blob([json], {type: "octet/stream"});
//url = window.URL.createObjectURL(blob);
var encodedUri = encodeURI("data:text/plain;charset=utf-8," + json);
a.setAttribute("href",encodedUri);
if ($scope.selectedRows.length === 1) {
commonFactory.getInstanceByUID($scope.domainUID, $scope.classUID, $scope.className, $scope.selectedRows[0], $scope.isCoreComponents).then(function (inst) {
a.setAttribute("download", inst[0]._fields[0].properties.Name+".json");
a.click();
window.URL.revokeObjectURL(url);
});
} else {
a.download = $scope.className+".json";
a.click();
window.URL.revokeObjectURL(url);
}
});
} else {
toastrFactory.warning('Please select at least one item to Export', 'Warning');
}
}