我在 webpack (刺激框架)中使用DataTables 。
我用 yarn 安装 jQuery 和 Datatables:
yarn add jquery --dev
yarn add jszip --dev
yarn add datatables.net --dev
yarn add datatables.net-dt --dev
yarn add datatables.net-buttons-dt --dev
yarn add datatables.net-responsive-dt --dev
yarn add datatables.net-select-dt --dev
现在我在 Stimulus 中创建一个控制器:
import {Controller} from 'stimulus';
import $ from 'jquery';
import 'jszip';
import 'datatables.net';
import 'datatables.net-dt';
import 'datatables.net-buttons-dt';
import 'datatables.net-responsive-dt';
import 'datatables.net-select-dt';
export default class extends Controller {
connect() {
$('#data-tables').dataTable();
}
}
当我在控制台中打开页面时显示错误:
Uncaught TypeError: Cannot read property 'ext' of undefined
at dataTables.buttons.js:42
at Object.<anonymous> (dataTables.buttons.js:9)
at dataTables.buttons.js:10
at Object../node_modules/datatables.net-buttons/js/dataTables.buttons.js (dataTables.buttons.js:30)
at __webpack_require__ (bootstrap:18)
at buttons.dataTables.js:8
at Object../node_modules/datatables.net-buttons-dt/js/buttons.dataTables.js (buttons.dataTables.js:34)
at __webpack_require__ (bootstrap:18)
at Module../node_modules/@symfony/stimulus-bridge/lazy-controller-loader.js!./assets/controllers/datatables_controller.js (cmad_lo_controller.js:89)
at __webpack_require__ (bootstrap:18)
我该如何解决这个问题?