/**
* @function 树数据转换数组类型
*/
const treeToArray = (node) => {
let result = [];
node.forEach((item) => {
if (Array.isArray(item.children)) {
result.push({ position_id: item.id, cost_amount: item.cost_amount ? item.cost_amount : null });
result = result.concat(treeToArray(item.children));
} else {
result.push({ position_id: item.id, cost_amount: item.cost_amount ? item.cost_amount : null });
}
});
return result;
};
js多维数组转换一维数组
最新推荐文章于 2024-10-01 20:12:28 发布