当前位置:网站首页>将同级数据处理成树形数据
将同级数据处理成树形数据
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>
边栏推荐
- Promise学习(三)Promise的几个关键性问题 -- 状态改变、执行顺序与机制、多任务串联、异常穿透、中断promise链
- 正则表达式
- 博弈论(Depu)与孙子兵法(42/100)
- JS 中的 undefined 和 null 的区别
- The four methods of judging JS data type
- Favorites|Mechanical Engineer Interview Frequently Asked Questions
- 新书上市 |《谁在掷骰子?》在“不确定性时代”中确定前行
- Mini Program Graduation Works WeChat Food Recipes Mini Program Graduation Design Finished Products (3) Background Functions
- 语音聊天app源码——语音聊天派对
- 深度学习 | MATLAB实现GRU门控循环单元gruLayer参数设定
猜你喜欢
Mini Program Graduation Works WeChat Food Recipes Mini Program Graduation Design Finished Products (3) Background Functions
STM32 CAN filter configuration details
xss-labs靶场挑战
大众碰到点评的一个字体反爬,落地技术也是绝了
OpenHarmony高校技术俱乐部计划发布
在线GC日志分析工具——GCeasy
【公开课预告】:超分辨率技术在视频画质增强领域的研究与应用
利用正则表达式的回溯实现绕过
各位大拿,安装Solaris 11.4操作系统,在安装数据库依赖包的时候包这个错,目前无原厂支持,也无安装盘,联网下载后报这个错,请教怎么解决?
解决vscode输入! 无法快捷生成骨架(新版vscode快速生成骨架的三种方法)
随机推荐
力扣解法汇总1374-生成每种字符都是奇数个的字符串
Pytest e-commerce project combat (below)
Tencent Cloud Native: Service Mesh Practice of Areaki Mesh in the 2022 Winter Olympics Video Live Application
JS数据类型转换完全攻略
【倒计时5天】探索音画质量提升背后的秘密,千元大礼等你来拿
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)
sql中ddl和dml(数据库表与视图的区别)
万字解析:vector类
Deep understanding of Istio - advanced practice of cloud native service mesh
NIO‘s Sword(思维,取模,推公式)
Small application project works WeChat gourmet recipes applet graduation design of finished product (1) the development profile
程序员如何优雅地解决线上问题?
如何获取微信视频号的地址(微信公众号的链接地址)
ACL 2022 | 文本生成的相关前沿进展
leetcode每日一题:字符串压缩
【社区明星评选】第24期 8月更文计划 | 笔耕不辍,拒绝躺平!更多原创激励大礼包,还有华为WATCH FIT手表!
轮询和长轮询的区别
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
语音聊天app源码——语音聊天派对
稀疏表示--学习笔记