Angular7:数据表未在网格中显示数据

时间:2018-12-14 06:17:38

标签: angular laravel datatable angular-datatables

我的数据表未在网格中显示任何JSON数组结果。 另外,控制台中没有错误,PHP文件也根据所需的有效格式返回了一个数组。
我的数据表版本是7.0.0
这是我的代码。

list.componenet.ts

export class EmployeelistComponent implements OnInit {
    dataTable: any;
    dtOptions: any;

    @ViewChild('dataTable') table;

    constructor(public hrService: HrService,
    public ngxSmartModalService: NgxSmartModalService,
    private toastr: ToastrService,
    public router: Router) {

        this.userToken = localStorage.getItem('token');
    }

    ngOnInit(): void {
        const data = {'token': this.userToken};

        this.dtOptions = {
            "ajax": {
                type: 'POST',
                dataSrc: "",
                data: data,
                url: 'http://127.0.0.1:8000/api/get-ist/'
            },
            columns: [
            {
                title: 'Emp ID',
                data: 'employee_number'
            },
            {
                title: 'Employee Name',
                data: 'name'
            },
            {
                title: 'Email',
                data: 'email'
            }
            ]
        };
        this.dataTable = $(this.table.nativeElement);
        this.dataTable.DataTable(this.dtOptions);
    }

}

这是我的HTML文件

<div class="widget-content no-padding">
   <table #dataTable class="display" style="width:100%">
   </table>
</div>

此处是Laravel API的输出

{data: [{employee_number: "1", name: "First name", email: "email@localhost"}]}

0 个答案:

没有答案