风华正茂、时光流逝、真爱时光、努力创建辉煌。

递归,

 

  let dataFormat = (data, parentDept = 0) => {
                data.map(item => {
                    item.dept = parentDept + 1;
                    item.Duration = !!item.planDrtn ? (item.nodeType == "task" && item.taskType == 3) ? 0 : item.planDrtn : '';
                    item.PercentComplete = item.PercentComplete !== null ? item.PercentComplete : '';
                    item.Critical = item["critical"] == 1 ? 1 : 0
                    item.Start = item.planStartTime + "T00:00:00"
                    item.Finish = item.planEndTime + "T23:59:59"
                    item.Baseline = [{ Start: item['blStartTime'] ? item.blStartTime + "T00:00:00" : null, Finish: item['blEndTime'] ? item.blEndTime + "T23:59:59" : null }]
                    if (item.dept > maxRowDept) {
                        maxRowDept = item.dept;
                    }
                    if (item.children && item.children.length !== 0) {
                        dataFormat(item.children, item.dept);
                    }
                });
            };
            dataFormat(data);

  

 

let arrFunc=(arr)=>{
                arr.map(item => {
                    item.taskCode = item.code
                    item.taskName = item.Name
                    let obj={
                        ...item
                    };
                    this.newCopy.push(obj)
                    if (item.children) {
                        arrFunc(item.children)
                    }
                });
        
            }

  

 

 var res = [];
    function flatten(arr) {
        arr.map(item => {
            let obj={
                ...item
            };
            res.push(obj)
            if (item.chile) {
                flatten(item.chile)
            }
        });
        
    }

    var arr = [

        {
            id: "55",
            name: "qqq",
            chile: [
                {
                    id: "55_1",
                    name: "qqq_1",
                    chile: [{
                        id: "55_2",
                        name: "qqq_2",
                    }]
                },
                {
                    id: "56_1",
                    name: "qq6_1",
                    chile: [{
                        id: "56_2",
                        name: "qq6_2",
                    }]
                }
            ]
        }

    ]


    console.log(res, '01')
    console.log(flatten(arr), '02')
    console.log(res, '03')

  

 

posted @ 2020-03-05 14:04  野马,程序源改造新Bug  阅读(91)  评论(0编辑  收藏  举报