我有这样的东西:

<table id="thatTable" class="table toggle-circle">
  <thead>
  <tr>
    <th>ID</th>
    <th>FieldA</th>
    <th data-hide="all">FieldB</th>
    <th data-hide="all">FieldC</th>
  </tr>
  </thead>
  <tbody>
  </tbody>
  <tfoot>
  <tr>
      <td colspan="4">
          <div class="text-right">
              <ul class="pagination"></ul>
          </div>
      </td>
  </tr>
  </tfoot>
</table>

然后像这样的JS:
var fillThatTable = function (list) {
    $.each(list, function (index, item) {
        $('#thatTable tbody').append($('<tr>')
            .append($('<td>').text(item.ID))
            .append($('<td>').text(item.FieldA))
            .append($('<td>').text(item.FieldB))
            .append($('<td>').text(item.FieldC))
            )
        );
    });
};

一切正常,表获取数据并全部显示。当我想将footable()设置到该表时,就会出现问题,例如:
$(document).ready(function () {
    fillThatTable();
    $('#thatTable').footable();
});

我得到的不是漂亮的东西,而是一个平均过滤表,就像我没有把它放在$('#thatTable').footable()。我查过JS是进口的。可能是因为这张桌子里没有任何东西吗?我错过了什么?
梦想:
javascript - 如何在从JSON中填充JS的表中进行合理的工作?-LMLPHP
现实:
javascript - 如何在从JSON中填充JS的表中进行合理的工作?-LMLPHP

最佳答案

我已经更新了PM的小提琴,以便更方便地使用脚踏:http://jsfiddle.net/0pb4x7h6/1
如果html更改为:

<table id="thatTable" class="table toggle-circle">
  <thead>
  <tr>
    <th data-name="ID">ID</th>
    <th data-name="FieldA">FieldA</th>
    <th data-name="FieldB" data-breakpoints="all">FieldB</th>
    <th data-name="FieldC" data-breakpoints="all">FieldC</th>
  </tr>
  </thead>
  <tbody>
  </tbody>
  <tfoot>
  <tr>
      <td colspan="4">
          <div class="text-right">
              <ul class="pagination"></ul>
          </div>
      </td>
  </tr>
  </tfoot>
</table>

然后可以将脚本简化为:
$(document).ready(function () {
    var list = [
    {"ID":"1","FieldA":"A1","FieldB":"B1","FieldC":"C1"},
    {"ID":"2","FieldA":"A2","FieldB":"B2","FieldC":"C2"},
    {"ID":"3","FieldA":"A3","FieldB":"B3","FieldC":"C3"}
    ];

    // No need for this
    //fillThatTable();
    $('#thatTable').footable({
        rows: list
    });
});

关于javascript - 如何在从JSON中填充JS的表中进行合理的工作?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/52434297/

10-10 01:17