下面的代码在chrome中有效,但是由于表达式=>
,它在IE 11中出现语法错误。
我使用了=>
表达式来过滤数据。
错误:第xx行的Javascript严重错误...... \ nSCRIPT1002:语法 错误并引发警报,在Visual Studio中停止调试
任何建议将不胜感激。
谢谢。
function customExportCSV(evt) {
var data = propertylayer._graphicsVal;
var csv = convertArrayOfObjectsToCSV({
data: data
});
if (!csv.match(/^data:text\/csv/i)) {
csv = 'data:text/csv;charset=utf-8,' + csv;
}
//var blob = new Blob([csv], { type: "text/csv" });
//if (navigator.msSaveBlob) { // IE 10+
// //var blob = new Blob([csv], { type: 'text/csv;charset=utf-8;' });
// //navigator.msSaveBlob(blob, "Exportdata.csv");
// navigator.msSaveBlob(blob, "csvname.csv")
//}
var encodedUri = encodeURI(csv);
var link = document.createElement('a');
link.setAttribute('href', encodedUri);
link.setAttribute('download', "Exportdata.csv");
link.click();
}
function convertArrayOfObjectsToCSV(value) {
var result, ctr, keys, columnDelimiter, lineDelimiter, data;
data = Array.from(new Set(value.data)).filter(d => d).map(d => d.attributes) || null;
if (!data || !data.length) {
return null;
}
columnDelimiter = value.columnDelimiter || ',';
lineDelimiter = value.lineDelimiter || '\n';
keys = Object.keys(data[1]);
result = '';
result += keys.join(columnDelimiter);
result += lineDelimiter;
data.forEach(function (item) {
ctr = 0;
keys.forEach(function (key) {
if (ctr > 0)
result += columnDelimiter;
result += item[key];
ctr++;
});
result += lineDelimiter;
});
return result;
}
答案 0 :(得分:0)
Arrow function(=>
)是IE11不支持的ES6语法。您只需要用旧的ES5 function expression语法替换它即可。
function convertArrayOfObjectsToCSV(value) {
var result, ctr, keys, columnDelimiter, lineDelimiter, data;
data = Array.from(new Set(value.data)).filter(function(d){return d;}).map(function(d){return d.attributes;}) || null;
if (!data || !data.length) {
return null;
}
}