を切り替えた後、適切に初期化しませselectpickerとのDataTableだからここにあなたが最初にそれをロードしたとき、私のページは次のようになります。切り替えた後 角度2 - ルート
これは、この不気味壊れた部分のコードです:
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);
});
}
誰でも考えがあれば、気をつけてください。あなたが世話をする必要があるいくつかのポイントがあります
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();
});
});
}
驚くばかり、私は明日それを試してみましょう。ありがとう。 –
私のために働かない。 –