element-ui树形 数据嵌套处理

@check="check"



import * as _ from 'underscore';//引入underscore
check(e1, e2) {
    let oridata = e2.checkedNodes;
    let halfs = this.$refs.searchTree.getHalfCheckedNodes(true);
    halfs.map((item) = >{
        oridata.push({
            isLeaf: item.isLeaf,
            orgCode: item.orgCode,
            orgLevel: item.orgLevel,
            orgName: item.orgName,
            parent: item.parent,
            parentLevel: item.parentLevel
        })
    });
    let tdata = _.map(oridata, (item_) = >{
        item_.data = _.filter(oridata, (subItem_) = >{
            if (!subItem_.parent) return false;
            return subItem_.parent === item_.orgCode;
        })
    });

    let outData = _.filter(oridata, (item_) = >{
        return ! _.findWhere(oridata, {
            orgCode: item_.parent
        })
    });

    this.checkData = {
        checkedKeys: e2.checkedKeys,
        checkedNodes: outData
    }
}

 

你可能感兴趣的:(web前端)