这是这个奇怪的损坏部分的代码:
ngOnInit(): void
{
$(document).ready(function() {
(<any>$("#the_table")).DataTable();
(<any>$('#selectpicker')).selectpicker();
}
if ($.isEmptyObject(this.route.snapshot.params) === false)
{
this.id = +(<any>this.route.snapshot.params).id;
}
let pass = {type: "reports"};
this.searchService.searchHttp( {type: "reports"} ).then( (response: any) =>
{
this.reports = response;
console.log(response);
});
}
这是“搜索”的代码,它没有被破坏。
ngOnInit(): void
{
$(document).ready(function() {
(<any>$('.selectpicker')).selectpicker();
});
this.tags = this.searchService.get_tags();
this.draw_table();
}
draw_table()
{
let json = JSON.stringify(this.tags);
this.table = (<any>$("#ajax_table")).DataTable({
"dom": 'Bfrtip',
"processing": true,
"ajax": {
"url": "app/php/search.php" + "?json=" + encodeURIComponent(json) + "&type=search",
},
"columns": [
{ "data": "id" },
{ "data": "ref" },
{ "data": "date" },
{ "data": "title" },
{ "data": "site" },
{ "data": "location" }
],
"filter": true,
"select": true,
"autoWidth": false,
"buttons": [
{
"text": "test",
action: () =>
{
console.log(table.rows( { selected: true } ).data());
let data = table.rows( { selected: true } ).data()[0];
data = (data) ? data : null;
this.router.navigate(['/main', data ]);
},
enabled: false
}
],
//"destroy": true
});
let table = this.table;
table.on( 'select', function () {
table.button(0).enable(true);
} );
table.on( 'deselect', function () {
table.button(0).enable(false);
});
}
如果有人有任何想法,请随时指出。
更新 尝试过的 NgZone:
ngOnInit(): void
{
if ($.isEmptyObject(this.route.snapshot.params) === false)
{
this.id = +(<any>this.route.snapshot.params).id;
}
let pass = {type: "reports"};
this.searchService.searchHttp( {type: "reports"} ).then( (response: any) =>
{
this.reports = response;
console.log(response);
this.ngZone.onStable.first().subscribe( () => {
(<any>$('#selectpicker')).selectpicker();
(<any>$("#the_table")).DataTable();
});
});
}