数据表未使用.html()生成的表填充

时间:2018-08-06 01:47:12

标签: jquery ajax datatables

我正在尝试使用.html()生成数据表内容,但是并未将其实现为实际数据。它会添加行,但是它们不可搜索或无法排序。它在生成的结果上方显示“表中没有可用数据”。如何在数据表中正确显示生成的数据?

JSfiddle

JS

//Payment history
$.ajax({
  url: "https://zelcash.voidr.net/api/payments",
  dataType: 'json',
  success: function(data) {

    var _miner = "t1XHpNtYY2N3EMDRoX9RM2hq4DWWPZSmawJ";

    var addr = _miner;

    for (var i = 0; i < data.length; i++) {

      //Name
      console.log(data[i].name);

      var payments = data[i].payments;
      for (var j = 0; j < payments.length; j++) {

        if (payments[j].amounts[_miner]) {

          //Time
          //console.log(payments[j].time);
          var date = payments[j].time;
          var date = new Date(parseInt(date));
          var date = date.toGMTString();

          //blocks
          var block = [];
          var blocks = payments[j].blocks;
          for (var b = 0; b < blocks.length; b++) {
            //console.log(blocks[b])
            block.push(blocks[b]);
          }

          //txid
          var txid = payments[j].txid;

          //amount
          //console.log(payments[j].amounts[_miner]);
          var amount = payments[j].amounts[_miner].toFixed(8);

          var htmlToAdd = "";
          htmlToAdd = '<tr>';
          htmlToAdd+= '<td>'+block+'</td>';
          htmlToAdd+= '<td><a href=\"https://explorer.zel.cash/tx/'+txid+'\">'+amount+'</a></td>';
          htmlToAdd+= '<td>'+date+'</td>';
          htmlToAdd+= '</tr>';
          $("#boxesPayments").html($("#boxesPayments").html()+htmlToAdd);

          //document.querySelector('#boxesPayments').innerHTML += '<tr><td>'+block+'</td><td><a href=\"https://explorer.zel.cash/tx/'+txid+'\">'+amount+'</a></td><td>'+date+'</td></tr>';

        }
      }
    }

  },
  error: function() {
    //alert("Was unable to get info!");
  }
});


$(document).ready(function() {
  $('#myTable').DataTable();
});

0 个答案:

没有答案