如何修复数据表初始化错误?

时间:2017-07-27 14:01:22

标签: javascript jquery ajax datatables

我编写了一个函数,它进行一次ajax调用并获取数据并创建一个表。我一次又一次地调用这个函数。但是这样做我正在重新初始化表错误。有人请帮我修复问题。

功能:



function getLibraryFilesStudent() {
  var reqBody = {
    "uploader": Cookies.get('user')
  };
  $.ajax({
    url: '../library/libraryfilegetlist',
    data: JSON.stringify(reqBody),
    dataType: 'json',
    headers: {
      "Content-Type": "application/json",
      "Accept": "application/json"
    },
    error: function(data) {
      console.log(data);
    },
    success: function(data) {
      if (data.length) {
        var trHTML = [];
        for (var i = 0; i < data.length; i++) {
          var test = '<input type="radio" class="radio" name="selectFile" value=' + data[i].id + "," + data[i].keyword + ",flag=1" + '>';
          trArr = [data[i].name, data[i].keyword, test]
          trHTML.push(trArr);
          if (data.length == trHTML.length) {
            $('#lFileList').DataTable({
              data: trHTML,
              bSort: false,
              pageLength: 4,
              columns: [{
                  title: "Name"
                },
                {
                  title: "keyword"
                },
                {
                  title: "Action"
                }
              ]
            });
          }
        }
      }
    },
    type: 'POST'
  });
}
&#13;
&#13;
&#13;

0 个答案:

没有答案