我是Angular 4的新手,我正在尝试按照ngx-datatable github中定义的方法实现ngx-datatble,并且我能够填充表格,但是当我尝试填充表格时,我的混乱就开始了。来自JSON对象的数据。 行和列数组与“name”属性绑定,同样显示为标题。但在实际的JSON中,我们将使用驼峰式命名约定。如何使用正确的标头填充该数据。
请建议,任何帮助将不胜感激.. !!!
先谢谢
请在下面找到我的代码:
HTML
<div>
<ngx-datatable
[rows]="rows"
[columns]="columns">
</ngx-datatable>
</div>
TS文件
rows = [
{ Firstname: 'Austin', gender: 'Male', company: 'Swimlane' },
{ name: 'Dany', gender: 'Male', company: 'KFC' },
{ name: 'Molly', gender: 'Female', company: 'Burger King' },
];
columns = [
{ prop: 'Firstname' },
{ name: 'Gender' },
{ name: 'Company' }
];
目标JSON
[{
"firstName":"abc",
"lastName":"xyz",
"address_1":"lorem ipsum",
"address_2":"and so on"
},{
"firstName":"abc",
"lastName":"xyz",
"address_1":"lorem ipsum",
"address_2":"and so on"
},{
"firstName":"abc",
"lastName":"xyz",
"address_1":"lorem ipsum",
"address_2":"and so on"
}]
答案 0 :(得分:2)
columns = [
{
prop: 'Firstname', // prop will bind to the json property
name : 'First Name' // You can define the name here
// ( Column label. If none specified, it will use the prop value and decamelize it. )
},
{ name: 'Gender' },
{ name: 'Company' }
];
详细信息: Read