【问题标题】:TypeError: Cannot read property 'style' of undefined DataTable AngularTypeError:无法读取未定义 DataTable Angular 的属性“样式”
【发布时间】:2020-10-20 13:56:42
【问题描述】:

我正在做这个项目,突然初始化后 DataTable 开始保持undefined,由于某种原因它也没有初始化。

这就是我的使用方式:

declare var $;

export ClassName implements OnInit {
    dataTable: any;
    ngOnInit(){
        this.dataTable = $('#table').DataTable({
          processing: true,
          ordering: false,
          pageLength: 10,
          language: this.getLanguages(),
          searching: false,
          dom: 't',
          paging: true,
          columns: comp.getColumns(), // returns columns
          createdRow: ( row, data, dataIndex) => {
            /* code */
          }
        });
    // code doesn't come here
    }
}

控制台上的错误是;

core.js:5828 ERROR TypeError: Cannot read property 'style' of undefined
    at _fnCalculateColumnWidths (datatables.bundle.js:5601)
    at _fnInitialise (datatables.bundle.js:4715)
    at loadedInit (datatables.bundle.js:1294)
    at HTMLTableElement.<anonymous> (datatables.bundle.js:1306)
    at Function.each (vendors.bundle.js:1290)
    at jQuery.fn.init.each (vendors.bundle.js:1125)
    at jQuery.fn.init.DataTable [as dataTable] (datatables.bundle.js:869)
    at jQuery.fn.init.$.fn.DataTable (datatables.bundle.js:15123)
    at comp.ngOnInit (comp.ts:149)
    at callHook (core.js:3892)

我在网上搜索过它,但找不到解决我问题的答案。正如我之前所说,这突然成为一个问题,而我没有更改 DataTable 的某些内容..

提前谢谢大家。

【问题讨论】:

    标签: angular typescript datatable


    【解决方案1】:

    发生这种情况是因为 comp.getColumns() 内部发生错误,导致 dataTable 无法初始化。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-11-29
      • 2018-10-29
      • 2021-07-21
      • 2018-05-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多