Post方法未在dtoption数据表js中运行

问题描述 投票:0回答:1

我有一种方法可以通过发布信息来吸引用户,而我正在使用在网络核心中消耗Web API的datable。但是post方法永远不会执行。它甚至不打印console.log('executing ...');。可能会发生什么? (没有服务器端的数据表可以完美工作)

HTML

 <table id="tableList" datatable [dtOptions]="dtOptions"  class="table table-bordered table-hover table-striped" *ngIf="elementList!=null">

组件

dtOptions: DataTables.Settings = {};

ngOnInit() {
const that = this;
const headers = new HttpHeaders({
  'Content-Type': 'application/json',
  'x-api-key': environment.apiKey,
  CustomToken: localStorage.getItem('customToken')
});
const options = { headers };
that.dtOptions = {
  pagingType: 'full_numbers',
  pageLength: 2,
  serverSide: true,
  processing: true,
  ajax: (dataTablesParameters: any, callback) => {
    console.log('executing....');
    that.http
      .post<DataTablesResponse>(
        'http://localhost:5000/api/Users/GetList',
        null, options
      ).subscribe(resp => {
        that.elementList = resp.data;

        callback({
          recordsTotal: resp.recordsTotal,
          recordsFiltered: resp.recordsFiltered,
          data: []
        });
      });
  },
 // columns: [{ data: 'id' }, { data: 'firstName' }, { data: 'lastName' }]
};

}

angular angular8 angular-datatables
1个回答
0
投票

您应该将其命名为this.dtOptions而不是that.dtoptions。

example here

© www.soinside.com 2019 - 2024. All rights reserved.