【问题标题】:this.title is not a function on datatablesthis.title 不是数据表上的函数
【发布时间】:2019-01-24 11:07:46
【问题描述】:

我在 Angular7 上使用 DataTables。我在 .ts 文件上有 js 函数。我得到“this.title 不是函数”错误。

我的视图文件中的代码如下:

$(document).ready(function () {
    $('#example').DataTable({
        ...
        initComplete: function () {
            const that = this;
            that.api().columns().every(function (index) {
                var e;
                switch (this.title()) {
                    case "Description":
                        e = $('<input type="text" class="form-control form-control-sm form-filter m-input" data-col-index="' 
                            + this.index() + '"/>');
                        break;
                }
            });
        }
    });
});

【问题讨论】:

  • 嗨,你能告诉我你的 this.title。它是方法还是变量?我认为那是错误。
  • @KarnanMuthukumar 嗨,它不在我的 .ts 文件中。它应该是 datatables.js 中的一个函数。我导入了 datatables.net,但仍然出现错误。
  • 好像column().title()plugin你注册了吗?

标签: javascript angular datatables


【解决方案1】:

如果您尝试修改与列标题对应的 DOM 元素,您可能需要使用column().header() 方法。所以你的this.title() 应该是this.header().textContent

【讨论】:

  • 不客气,别忘了标记您的问题已回答。如果您指的是列中单元格的值,则为column().data() 方法。
【解决方案2】:

您可以使用它来获取列名,它适用于我。

    var table = $("#extable").DataTable();
    var column_name= table.column(0).header().innerText;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-03-10
    • 1970-01-01
    • 2014-04-21
    • 1970-01-01
    • 2020-06-29
    • 2016-01-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多