angualr -6/js 中 ngx 数据表的嵌套 json 数据最小化 [英] nested json data minipulation for ngx datatable in angualr -6 / js

查看:24
本文介绍了angualr -6/js 中 ngx 数据表的嵌套 json 数据最小化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个 ngx 数据表,它从嵌套数组动态创建列,这在一些研究中是不可能的 - 所以为了达到我想要的结果,我必须用我需要的键/值来展平我的嵌套数组嵌套对象到我的父对象中.

我需要处理我的数据,以便我的最终结果是一个平面数组,并且包含嵌套数组收入中每个对象的行项目,'abbreviation' 是键,'amount' 是价值..

<预><代码>[{员工uuid:978f37df-7e07-4118-be93-d82507ce5c46,员工代码:JB00024,全名:Thulisile Sandra,姓氏:Bhekiswayo收益:[{缩写:NT HRS"金额:45.00"钱:假名称:正常时间HRS"时间:真实唯一:7d783469-717e-408a-bc3c-93115cb632dd_true"uuid:7d783469-717e-408a-bc3c-93115cb632dd"值:45.00"},{缩写:OT HRS"金额:25.00"钱:假名称:正常时间HRS"时间:真实唯一:7d783469-717e-408a-bc3c-93115cb632dd_true"uuid:7d783469-717e-408a-bc3c-93115cb632dd"值:45.00"}],终止假}...]

我想看起来像这样:

<预><代码>[{员工uuid:978f37df-7e07-4118-be93-d82507ce5c46,员工代码:JB00024,full_name: Thulisile Sandra,姓氏:Bhekiswayo,NT HRS: '45.00',OT HRS, '25.00',终止:假}...]

我不知道该怎么做,我试过减少和映射函数,但没有成功.我可以使用 Object.assign 将嵌套数组添加到父对象,但这需要整个对象,我需要从该对象创建一个新参数..

任何帮助将不胜感激..

解决方案

您可以为此使用 es6 解构,只需公开您需要的任何属性,然后重新组合"到您想要的对象形状.例如:

return myEmployeeArray.map(employee => {const {earn } = 员工赚取地图(字段 => 字段.缩写)myDesiredObject = { fieldA:employee.abbreviation....fieldE:field.abbreviation}}

这将为您提供嵌套字段之一

I am trying to create a ngx datatable that creates columns dynamically from nested arrays, which with some research is not possible - so to achieve my desired result, I must flatten my nested arrays with the key / values that i need from each nested object into my parent object.

I need to manipulate my data so that my end result is a flat array and contains a line item for each object in the nested array earnings with 'abbreviation' being the key and 'amount' being the value..

I.e

[
{
employee_uuid:  978f37df-7e07-4118-be93-d82507ce5c46,
employee_code:  JB00024,
full_name:  Thulisile Sandra,
last_name:  Bhekiswayo
earnings:[{
    abbreviation: "NT HRS"
    amount: "45.00"
    money: false
    name: "Normal Time HRS"
    time: true
    unique: "7d783469-717e-408a-bc3c-93115cb632dd_true"
    uuid: "7d783469-717e-408a-bc3c-93115cb632dd"
    value: "45.00"
},
{
    abbreviation: "OT HRS"
    amount: "25.00"
    money: false
    name: "Normal Time HRS"
    time: true
    unique: "7d783469-717e-408a-bc3c-93115cb632dd_true"
    uuid: "7d783469-717e-408a-bc3c-93115cb632dd"
    value: "45.00"
}],
terminated  false
}
...
]

I'd like to look like this:

[
{
employee_uuid:  978f37df-7e07-4118-be93-d82507ce5c46,
employee_code:  JB00024,
full_name:  Thulisile Sandra,
last_name:  Bhekiswayo,

NT HRS: '45.00',
OT HRS, '25.00',

terminated:false
}
...
]

I am not sure how to go about this, I've tried reducing and map functions but no success.. I can add the nested arrays to the parent object with Object.assign but that takes the whole object, I need to create a new parameter from that object..

Any help would be hugely appreciated..

解决方案

You can use es6 destructuring for this, simply expose whatever properties you need and then "recompose" then into the object shape you want. For example:

return myEmployeeArray.map(employee => { 
const {earn } = employee
earn.map(field => field.abbreviation)
myDesiredObject = { fieldA: employee.abbreviation....fieldE:field.abbreviation} 
}

This would get you one of your nested fields

这篇关于angualr -6/js 中 ngx 数据表的嵌套 json 数据最小化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆