美文网首页
代码规范--树形项目

代码规范--树形项目

作者: Romyo | 来源:发表于2018-04-04 17:35 被阅读0次

    1.递归如何停止?

    if(...){
       ...
      }
    else if(...){
       递归
    }
    

    2.递归是否有返回值?

     ----可使用Object的引用类型特性,无需return
    
    利用数组的引用类型特性 利用对象的引用类型特性

    3.平铺和递归的使用场景?

    ===== >>>>  3.1 递归适用场景,一层下面套多层 <<<<======
    数据结构形式:
    [{
        "type": "RuleActionInstance",
        "key": "0",
        "inputValue": "",
        "children": [{
            "type": "webRuleConditions",
            "key": "0-0",
            "value": "条件",
            "children": []
        }, {
            "type": "webRuleAction",
            "key": "0-1",
            "value": "实例",
            "children": []
        }]
    }]
    
    ======>>>> 3.2 平铺的适用场景,就是一个数组里面的数据结构 <<<<===
    
    平铺的数据结构形式
    ======== >>>>  将递归转换为平铺函数 
    let transformTreeNodeToPlaintArray = (allRuleChild, plainArray) => {
        for (let i = 0, length = allRuleChild.length; i < length; i++) {
            plainArray.push(allRuleChild[i]);
            if (!!allRuleChild[i].children) {
                transformTreeNodeToPlaintArray(allRuleChild[i].children, plainArray);
            }
        }
    }
    

    相关文章

      网友评论

          本文标题:代码规范--树形项目

          本文链接:https://www.haomeiwen.com/subject/wmokhftx.html