2

我是 Angular 4 的新手,我正在尝试通过遵循ngx-datatable github中定义的方法来实现 ngx-datatble,并且我能够填充表,但是当我尝试从 JSON 填充数据时,我的困惑开始了目的。行和列数组与“名称”属性绑定,并且显示为标题。但在实际的 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"
}]
4

1 回答 1

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' }

];

欲了解更多详情:阅读

于 2018-02-19T07:26:33.343 回答