当前位置:网站首页>Process sibling data into tree data
Process sibling data into tree data
2022-08-01 12:02:00 【snow xiaoxin】
Process sibling data into tree data
<script>
const oldArray = [
{
batchNo: "1",
factoryCnName: "苹果",
goodsCnName: "pingguo",
inputNum: 1,
},
{
batchNo: "1",
factoryCnName: "苹果",
goodsCnName: "pingguo",
inputNum: 3,
},
{
batchNo: "1",
factoryCnName: "梨子",
goodsCnName: "lizi",
inputNum: 3,
},
{
batchNo: "1",
factoryCnName: "梨子",
goodsCnName: "lizi",
inputNum: 3,
},
{
batchNo: "2",
factoryCnName: "苹果",
goodsCnName: "pingguo",
inputNum: 3,
},
];
const inStoreTabData = TabFormartFun(oldArray);
console.log(inStoreTabData, "inStoreTabData");
//Process inbound and outbound form data
function TabFormartFun(arr) {
const data1 = dataformart1(arr, "goodsCnName");
const data2 = dataformart2(data1, "factoryCnName");
const result = dataformart3(data2, "batchIdNo");
return result;
}
//格式化表格数据
function dataformart1(beforeData, name) {
var tempArr = [];
var afterData = [];
for (var i = 0; i < beforeData.length; i++) {
if (tempArr.indexOf(beforeData[i][name]) == -1) {
afterData.push({
Name: beforeData[i][name],
show: i == 0 || name == "batchIdNo" ? true : false,
children: [beforeData[i]],
});
tempArr.push(beforeData[i][name]);
} else {
for (var j = 0; j < afterData.length; j++) {
if (afterData[j].Name == beforeData[i][name]) {
afterData[j].children.push(beforeData[i]);
break;
}
}
}
}
return afterData;
}
function dataformart2(beforeData, name) {
beforeData.forEach((element, index) => {
var afterData = [];
var tempArr = [];
var ele = element.children;
var itemArr = dataformart1(ele, name);
beforeData[index].children = itemArr;
});
return beforeData;
}
function dataformart3(beforeData, name) {
beforeData.forEach((element, index) => {
var afterData = [];
var tempArr = [];
var ele = element.children;
var itemArr = dataformart2(ele, name);
//计算数量
itemArr.forEach((eve) => {
eve.children.forEach((item) => {
var total = 0;
item.children.forEach((e) => {
total = total + (e.inputNum - 0);
});
item.total = total;
});
});
beforeData[index].children = itemArr;
});
return beforeData;
}
</script>
边栏推荐
- 深度学习 | MATLAB实现一维卷积神经网络convolution1dLayer参数设定
- 博弈论(Depu)与孙子兵法(42/100)
- Qt get all files in a folder
- Why Metropolis–Hastings Works
- [CLion] CLion always prompts "This file does not belong to any project target xxx" solution
- A new generation of ultra-safe cellular batteries, Sihao Airun goes on sale starting at 139,900 yuan
- Hot review last week (7.25 7.31)
- leetcode/submatrix element sum
- 字体反爬之好租
- Favorites|Mechanical Engineer Interview Frequently Asked Questions
猜你喜欢
leetcode/子矩阵元素和
How to use DevExpress controls to draw flowcharts?After reading this article, you will understand!
MarkDown公式指导手册
爱可可AI前沿推介(8.1)
2022 Go生态圈 rpc 框架 Benchmark
数字化转型实践:世界级2B数字化营销的方法框架
[Open class preview]: Research and application of super-resolution technology in the field of video quality enhancement
用户体验 | 如何度量用户体验 ?
redis6 跟着b站尚硅谷学习
Audio and Video Technology Development Weekly | 256
随机推荐
用户体验 | 如何度量用户体验 ?
How to use DevExpress controls to draw flowcharts?After reading this article, you will understand!
Kaitian aPaaS mobile phone number empty number detection [Kaitian aPaaS battle]
Promise to learn several key questions (3) the Promise - state change, execution sequence and mechanism, multitasking series, abnormal penetration, interrupt the chain of Promise
【公开课预告】:超分辨率技术在视频画质增强领域的研究与应用
判断JS数据类型的四种方法
博弈论(Depu)与孙子兵法(42/100)
Qt get all files in a folder
新一代超安全蜂窝电池, 思皓爱跑上市13.99万元起售
[Community Star Selection] Issue 24 August Update Plan | Keep writing, refuse to lie down!More original incentive packages, as well as Huawei WATCH FIT watches!
回归预测 | MATLAB实现TPA-LSTM(时间注意力注意力机制长短期记忆神经网络)多输入单输出
【公开课预告】:超分辨率技术在视频画质增强领域的研究与应用
Promise学习(三)Promise的几个关键性问题 -- 状态改变、执行顺序与机制、多任务串联、异常穿透、中断promise链
R语言ggplot2可视化:使用ggpubr包的geom_exec函数执行geom_*函数(没有任何参数需要放置在aes中)
SCHEMA solves the puzzle
Promise learning (4) The ultimate solution for asynchronous programming async + await: write asynchronous code in a synchronous way
【社区明星评选】第24期 8月更文计划 | 笔耕不辍,拒绝躺平!更多原创激励大礼包,还有华为WATCH FIT手表!
C#/VB.NET 将PPT或PPTX转换为图像
在线GC日志分析工具——GCeasy
Why Metropolis–Hastings Works