Below code works in chrome, but it is getting syntax error in IE 11 because of expression =>
.
I used the =>
expression to filter data.
Error: Javascript critical error at line xx ......\nSCRIPT1002: syntax error and throws an alert stop debugging in Visual studio
Any suggestions will be appreciated.
Thanks.
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;
}
Arrow function (=>
) is a ES6 syntax which is not supported by IE11. You just have to replace it by the old ES5 function expression syntax.
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;
}
}