【发布时间】:2020-06-24 09:16:04
【问题描述】:
我通过 Api 从三个不同的查询中获取数据。我希望在没有重复数据的情况下合并数据。
This is my function where i am merging the data:
getStaffCount(data) {
if (data == null || data.results === null )
return [];
else
return data.results.StaffCount.map(m => ({ Name: m.Name, Accounts: m.Accounts })).
concat(data.results.RepProviderAccount.map(m => ({ Name: m.Name, Accnt: m.Accnt }))).
concat( data.results.ProviderAccount.map(m => ({ Name: m.Name, Account: m.Account })));
}
这是我的桌子:
<PowerTable Data={{ rows: this.getStaffCount(this.props.GridData) }} rowsPerPage={5} orderBy="Name" order="asc" >
<PowerColumn id='Name' columnName='Name' numeric={false} disablePadding={false} label='Profile Name' width={100}>
</PowerColumn>
<PowerColumn id='Accounts' columnName='Accounts' numeric={false} disablePadding={false} label='Staff Accounts' width={100}>
</PowerColumn>
<PowerColumn id='Account' columnName='Account' numeric={false} disablePadding={false} label='Provider Account' width={100} >
</PowerColumn>
<PowerColumn id='Accnt' columnName='Accnt' numeric={false} disablePadding={false} label='Rep Provider Account' width={100} >
</PowerColumn>
</PowerTable>
So in the above image same Profile Name(CNX MSL Platform) is coming twice. So is there any way i can merged those rows?
I want the Output in this way:
Profile Name Staff Provider Rep Provider
Cnx MSl Platform 2 1
Cnx Specilaity sales Platform 7 22
【问题讨论】:
-
如果你只显示json数据会更容易看到如何合并。
-
您只映射名称和帐户,Staff、RepProvider 和 Provider 来自哪里?以及您想如何合并它们,它们是按名称还是帐户合并?
-
@HMR 这些是列标签名称。 name 和 account 是数据库中的实际列名
-
@JoeLloyd 我正在从 SoQL 查询中获取数据。它是一个对象,但扩展运算符似乎不起作用
标签: javascript reactjs merge soql