1

如果我传入 DataTable,以下 JavaScript 可以正常t_dataSet工作,但如果我通过this.dataSet.

define( ['jquery', 'https://cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js'], function($, Datatables) {
"use strict";

function DatatablesSimpleList() {}

DatatablesSimpleList.prototype.draw = function( oControlHost ) {

    let htmlElement = oControlHost.container;
    htmlElement.innerHTML = '<table id="datatable_example" class="display" width="100%"></table>';

    var t_dataSet = [
        [ "Tiger Nixon" ],
        [ "Garrett Winters"],
        [ "Ashton Cox"]
    ];

    $(function () {
        $('#datatable_example').DataTable({
            data: t_dataSet,        // this works
            //data: this.dataSet,   // this does not work
            columns: [{ title: "Name" }]
        });

    });
};

DatatablesSimpleList.prototype.setData = function( oControlHost, oDataStore ) {

    this.dataSet = [
        [ "Tiger Nixon" ],
        [ "Garrett Winters"],
        [ "Ashton Cox"]
    ];
};

return DatatablesSimpleList;

});

关于为什么这不能按预期工作的任何想法?

4

0 回答 0