当前位置:网站首页>将同级数据处理成树形数据
将同级数据处理成树形数据
2022-08-01 11:33:00 【淋雪小新】
将同级数据处理成树形数据
<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");
//处理出入库表格数据
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>
边栏推荐
- xss漏洞学习
- 小程序插件如何帮助开发者受益?
- 解决vscode输入! 无法快捷生成骨架(新版vscode快速生成骨架的三种方法)
- Istio Meetup China:全栈服务网格 - Aeraki 助你在 Istio 服务网格中管理任何七层流量
- Envoy 源码流程图
- leetcode每日一题:字符串压缩
- Mini Program Graduation Works WeChat Food Recipes Mini Program Graduation Design Finished Products (3) Background Functions
- 深入理解 Istio —— 云原生服务网格进阶实战
- Promise学习(三)Promise的几个关键性问题 -- 状态改变、执行顺序与机制、多任务串联、异常穿透、中断promise链
- 监视网络连接的ss命令
猜你喜欢
C#/VB.NET 将PPT或PPTX转换为图像
图解MySQL内连接、外连接、左连接、右连接、全连接......太多了
[Open class preview]: Research and application of super-resolution technology in the field of video image quality enhancement
这是我见过写得最烂的Controller层代码,没有之一!
Promise to learn several key questions (3) the Promise - state change, execution sequence and mechanism, multitasking series, abnormal penetration, interrupt the chain of Promise
数字化转型实践:世界级2B数字化营销的方法框架
Promise学习(一)Promise是什么?怎么用?回调地狱怎么解决?
【讲座分享】“营收“看金融
Audio and Video Technology Development Weekly | 256
新一代超安全蜂窝电池, 思皓爱跑上市13.99万元起售
随机推荐
【无标题】
DBPack SQL Tracing 功能及数据加密功能详解
Favorites|Mechanical Engineer Interview Frequently Asked Questions
C#/VB.NET 将PPT或PPTX转换为图像
在线GC日志分析工具——GCeasy
pandas connects to the oracle database and pulls the data in the table into the dataframe, filters all the data from the current time (sysdate) to one hour ago (filters the range data of one hour)
冰冰学习笔记:gcc、gdb等工具的使用
(ES6 and above and TS) Map object to array
[5 days countdown] to explore the secret behind the great quality promotion, gift waiting for you to take of $one thousand
表达式引擎在转转平台的实践
深入理解 Istio —— 云原生服务网格进阶实战
MNIST是什么(plist是什么意思)
js中常用追加元素的几种方法:append,appendTo,after,before,insertAfter,insertBefore,appendChild
[Nodejs] fs module of node
Browser shortcut keys
如何利用DevExpress控件绘制流程图?看完这篇文章就懂了!
CAN通信的数据帧和远程帧
R language ggplot2 visualization: use the ggdensity function of the ggpubr package to visualize density plots, use the stat_central_tendency function to add mean vertical lines to the density and cust
jmeter
C语言实现!20000用4秒计算