AngularJs数据表Promise和点火数据表

时间:2019-03-01 10:42:50

标签: javascript angularjs promise datatables angular-datatables

我在用AngularJS填充数据表时遇到问题,

DataTables warning: table id=DataTables_Table_0 - Requested unknown parameter '0' for row 0, column 0. For more information about this error, please see http://datatables.net/tn/4

我从API返回的内容是使用Ignited Datatables

        data: Array(145)
          [0 … 99]
            0: {id: "0", uid: "21912"}
            1: {id: "1", uid: "22000"}
            2: {id: "1.2345666664667e32", uid: "21967"}
            3: {id: "1.2345676773423e30", uid: "21970"}
            4: {id: "1.2345676777777e20", uid: "21969"}
            5: {id: "1001", uid: "22008"}
          [100 … 144]
            100: {id: "PS1548080820", uid: "22117"}
            101: {id: "PS1548081358", uid: "22118"}
            102: {id: "PS1548082263", uid: "22119"}
        draw: 0
        recordsFiltered: "145"
        recordsTotal: "145"

我的Javascript正在使用诺言获得此信息,

 $scope.dtColumns = DTColumnBuilder.newColumn('id').withTitle('ID'),
                    DTColumnBuilder.newColumn('uid').withTitle('UID');

 $scope.dtOptions = DTOptionsBuilder.fromFnPromise(function() 
 {
     return ApiService.GetTableDate($scope.searchParams, $scope.currentPage, $scope.pageSize).then(function (result) 
     {
         return result.data;
     });
 })
 .withPaginationType('full_numbers')
 .withOption('deferRender', true)
 .withDisplayLength(10)
 .withOption('initComplete', function() { });

我的HTML在下面,

<table datatable="" dt-options="dtOptions" dt-columns="dtColumns"
            class="table table-bordered table-striped">
      <thead>
          <tr>
              <th>UID</th>
              <th>ID</th>
          </tr>
      </thead>
</table>

有人可以帮我解决我的问题吗?

非常感谢。

1 个答案:

答案 0 :(得分:0)

分配[]时缺少$scope.dtColumns,因此它不是数组。应该是:

$scope.dtColumns = [
  DTColumnBuilder.newColumn('id').withTitle('ID'),
  DTColumnBuilder.newColumn('uid').withTitle('UID')
];