0

我正在使用 requirejs 和带有按钮的数据表来导出 pdf 和 csv 报告。我在页面上遇到随机错误,尤其是在 IE11 上,例如:“无法设置未定义的属性 pdfMake”或“DataTable.Buttons 未定义”这是随机发生的,如果我刷新页面,错误就会消失。我认为这是因为我无法解决的依赖问题。有没有其他人遇到过这个问题?

我试图在 require js 'shim' 中设置依赖关系,但没有运气。

(function (window, requirejs) {
  'use strict';
  requirejs.config({
    waitSeconds: 20,
    baseUrl: window.appConfig.scriptsPath,
    paths: {
      hbs:['handlebars.min'],
      infobox:['infobox'],
      lo:['lodash.min'],
      daterange:['daterangepicker'],
      tabs:['tab.min'],
      sel2:['select2.min'],
      scrollbar: ['vendors/jquery.scrollbar.min'],
      dataTables: ['jquery.dataTables.min'],
      //DataTables core
      'datatables-cdn' : 'https://cdn.datatables.net/1.10.19/js/jquery.dataTables.min',
      'datatables-cdn-buttons' : 'https://cdn.datatables.net/buttons/1.5.2/js/dataTables.buttons.min',
      //Extra modules
      'datatables-cdn-buttons-flash' : 'https://cdn.datatables.net/buttons/1.5.2/js/buttons.flash.min',
      'datatables-cdn-jszip' : "https://cdnjs.cloudflare.com/ajax/libs/jszip/3.1.3/jszip.min",
      'datatables-cdn-pdfmake' : "https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.36/pdfmake.min",
      'datatables-cdn-vfsfont' : "https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.36/vfs_fonts",
      'datatables-cdn-button-html5' : "https://cdn.datatables.net/buttons/1.5.2/js/buttons.html5.min",
      gCharts:['loader'],
      ChartsJs:['Chart.bundle.min'],
      ChartsJsLabel:['Chart.PieceLabel.min'],
      amcharts:['amcharts/amcharts.min'],
      amchartsSerial:['amcharts/serial.min'],
      amchartsGauge:['amcharts/gauge.min'],
      amchartsExport:['amcharts/export/export.min'],
      jsPdf: ['jspdf'],
      html2canvas: ['html2canvas'],
      h2canvas: ['vendors/html2canvas'],
      canvasPlugin:['jquery.plugin.html2canvas'],
      canv:['canvg.min'],
      async: 'async'
    },
    shim: {
      'app.core.min': {
        deps: ['jquery']
      },
      ChartsJsLabel:{
        deps: ['ChartsJs']
      },
      autotable:{
        deps: ['jsPdf']
      },
      amchartsGauge:{
        deps: ['amcharts']
      },
      amchartsSerial:{
        deps: ['amcharts']
      },
      amchartsExport:{
          deps: ['amcharts']
      },
      daterange:{
        deps: ['jquery']
      },
      tabs:{
        deps: ['jquery']
      },
      jsPdf:{
        deps: ['jquery', 'html2canvas']
      },
      html2canvas:{
        deps: ['canvasPlugin']
      },
      infobox:{
        deps: ['async!https://maps.googleapis.com/maps/api/js?v=weekly&key=AIzaSyDX-6ZAspxTrtZknORO335Ist8cGKze4tI&callback=false']
      }
    },
    urlArgs: window.appConfig.assetHash
  });
  // Load the main app module to start the app
  requirejs(['jquery', 'app.core.min', 'lo'], function ($, app, _) {
    app();
    // disable jQuery Ajax call caching
    $.ajaxSetup({
      cache: false
    });
  });
}(window, requirejs));
var OWCS = {};

// 这是我的 javascript 文件

(function (define, window) {
  define(['./helpers', 'datatables-cdn', 'datatables-cdn-buttons' , 'datatables-cdn-buttons-flash', 'datatables-cdn-jszip', 'datatables-cdn-pdfmake', 'datatables-cdn-vfsfont', 'datatables-cdn-button-html5'],
function (helper) {
    'use strict';
      // my code ajax calls and datatable initialization
  });
}(define, window));

它在 chrome 和 firefox 上完美运行,但是,在 IE 上,它给出了如上所述的 javascript 错误。

4

0 回答 0