【发布时间】:2018-11-02 06:10:49
【问题描述】:
实际上我已经使用数据表通过 jquery 库以角度显示数据。
用户将搜索名称并假设如果输出出现,该用户将单击数据表的主体,我想在 console.log() 中显示这个单一的 JSON 数据。如何获得这种方法?
component.ts 文件
export class ProcessAssessmentComponent implements OnInit {
selections: Observable<Selection[]>;
dataTable: any;
clients: any[];
constructor(private http: HttpClient,private selectionService: SelectionService,private processAssesstmentService:ProcessAssesstmentService,private chRef: ChangeDetectorRef) { }
ngOnInit() {
this.http.get('http://localhost:8080/api/selections')
.subscribe((data: any[]) => {
this.clients = data;
this.chRef.detectChanges();
// Now you can use jQuery DataTables :
const table: any = $('table');
this.dataTable = table.DataTable();
});
}
}
component.html 文件
<table class="table table-bodered">
<thead>
<tr>
<th>Mag No</th>
<th>SelectionDate</th>
<th> SelectedBy</th>
<th>PanEximNumber</th>
<th>Name</th>
<th>Address</th>
<th>PhoneNumber</th>
<th>SelectionType</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let client of clients">
<td>{{client.selectionId}}</td>
<td>{{client.selectionDate}}</td>
<td>{{client.selectedBy}}</td>
<td>{{client.panEximNumber}}</td>
<td>{{client.name}}</td>
<td>{{client.address}}</td>
<td>{{client.phoneNumber}}</td>
<td>{{client.selectionType}}</td>
</tr>
</tbody>
</table>
【问题讨论】:
标签: javascript html angular typescript datatable