Post 方法不在 dtoption 数据表 js 中 运行
Post method does not run within dtoption datatable js
我有一个运行 post 来获取用户的方法,我正在使用在 net core 中消耗网络 api 的数据表。但是 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' }]
};
}
您应该将其命名为 this.dtOptions 而不是 that.dtoptions。
我有一个运行 post 来获取用户的方法,我正在使用在 net core 中消耗网络 api 的数据表。但是 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' }]
};
}
您应该将其命名为 this.dtOptions 而不是 that.dtoptions。