我從服務檔案中獲取了陣列資料,這里我的問題是在我的資料表中資料被正確系結,但分頁、搜索和排序在Dom中加載。
.html
<table class="table table-striped" datatable [dtOptions]="dtOptions" [dtTrigger]="dtTrigger" >
<thead>
<tr>
<th>UNIQUE_ID</th>
<th> ORGANISATION</th>
<th>CREATED</th>
<th>MODIFIED</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let organisation of organisationsList">
<td>{{organisation.OrganisationUid}}</td>
<td>{{組織機構.組織名稱}}</td>
<td>{{organisation.CreatedOn | date: 'dd-MMM-yyy hh:mm:ss a'}}</td>
<td>{{organisation.ModifiedOn | date: 'dd-MM-yyyy hh:mm:ss a'}}</td>
<td>
<button class="btn btn-primary" (click)="goToViewOrganisation(organization.Id)"><i class="icon-eye"> </i></button>
</td>
</tr>
</tbody>
</table>
component.ts
ngOnInit(): void {
this.dtOptions = {
pagingType: 'full_numbers',
順序。[2, 'desc'],
columnDefs: [{
目標。[4],
orderable: false,
}, {
目標。[2, 3],
型別:'日期
}]
};
this.loadOrganisationsList()。
}
loadOrganisationsList() {
this.orgService.getOrganisationsList().subscribe((res) => {
this.organizationsList = res['Data']['Organisations'];
this.dtTrigger.next()。
}, (err) => {
如果(err.status !==403) {
));
}
});
service.ts
getOrganisationsList() {
const organization = JSON.parse(localStorage.getItem('organization'))。
if (organization !== undefined && organisation !== null) {
回傳of(organization)。
} else {
const API_URL = `${this.env.apiUrl}/Organisations`。
return this.httpClient.get(API_URL).map((data: any) => {
localStorage.setItem('organization', JSON.stringify(data))。
回傳資料。
}).catch((error: any) => {
return Observable.throw(error)。
});
}
}
uj5u.com熱心網友回復:
為dtTrigger.next()添加了超時,就像下面的代碼:
loadOrganisationsList() {
this.orgService.getOrganisationsList().subscribe((res) => {
this.organizationsList = res['Data']['Organisations']。
setTimeout(function() {
this.dtTrigger.next()。
}.bind(this))。
}, (err) => {
如果(err.status !==403) {
}
});
}
uj5u.com熱心網友回復:
可能是datable在你從服務器獲得回應之前被激活了。
試著像下面這樣添加*ngIf:
<table class="table table-striped" *ngIf="organizationsList.length > 0" datatable [dtOptions]="dtOptions" [dtTrigger]="dtTrigger" >
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/307510.html
標籤:
上一篇:FIREBASE警告:使用一個未指定的索引。你的資料將被下載并在客戶端進行過濾
下一篇:在一個輸入框中使用陣列
