我正在尝试使用primeng dataTable。其中我在" jsonArray"中加载嵌套的JSON。如下:
{
"person_name": "Gaurav",
"personal_details":[{
"last_name":"patel",
"age":24
}],
"technical_details":[{
"roll_no":1,
"branch":"IT"
}]
}

//app.component.ts
import { Component } from '@angular/core';
import { AppService } from './app.service';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
jsonArray: any[]=[];
constructor(public AppSVC: AppService) { }
ngOnInit() {
this.AppSVC.getAppontmentJson().subscribe(res => {
if (!res.error_status) {
this.jsonArray = res;
}
});
}
}

//app.component.html
<p-dataTable [value]="jsonArray" reorderableColumns="true">
<p-column header="Last Name" field="personal_details.last_name"></p-column>
<p-column header="Age" field="personal_details.last_name"></p-column>
</p-dataTable>
&#13;
但是当我运行代码时,它显示错误:
错误类型错误:val.slice不是函数
我是角色2的新手
答案 0 :(得分:1)
似乎数据格式不正确。您需要为数据表分配一个数组。
[{
"person_name": "Gaurav",
"personal_details":{
"last_name":"patel",
"age":24
},
"technical_details":{
"roll_no":1,
"branch":"IT"
}
}]