将文本值导出为.csv时,IE11中“不允许在严格模式下分配只读属性”错误,Chrome浏览器工作正常

时间:2016-11-28 07:00:23

标签: javascript internet-explorer-11

将文本值导出为.csv时,IE11中的“严格模式下不允许对只读属性进行分配”错误,Chrome浏览器使用相同的代码正常工作。

以下是我的代码:

    define('mybiz.framework.csvsave',
         ['jquery', 'mybiz.framework.loggingservice', 'saveAs'], function ($,
         JL,    saveAs) {  
         'use strict';
         var logger = JL('mybiz.framework.csvsave');
         var generate = function (doc) {
         logger.info("about to save CSV document");
         var startTime = new Date();
         try {
         var textEncoder = new TextEncoder('utf-16le');
         var csvContentEncoded = textEncoder.encode([doc]);
         var bom = new Uint8Array([0xFF, 0xFE]);
         var out = new Uint8Array(bom.byteLength            +csvContentEncoded.byteLength);     
            out.set(bom, 0);
            out.set(csvContentEncoded, bom.byteLength);

            var csvBlob = new Blob([out], {type: 'text/csv'});
            saveAs(csvBlob, "los.csv");
        } catch (e) {
            logger.error("Error generating CSV: " + e.message + "\n" + e.stack);
        }
        var stopTime = new Date();
        logger.info("CSV generation completed in: " + (stopTime - startTime) + "ms");
    };
    return {
        generate: generate
    };
});  

以下代码调用上面的函数:

    self.saveExportCSV = function (data, event) {
                var columns = getColumnsToExport(self.columnsForExport());
                self.exportCSV({'columns': columns, 'generator':   
csvsave.generate, event: event});
            };

0 个答案:

没有答案