关于javascript:js-封装tree数据常用方法

38次阅读

共计 352 个字符,预计需要花费 1 分钟才能阅读完成。

      

       const filterTree = (options = {})=>{
        let ops = {data: options.data || [],
            exclude: options.exclude || {},}
        let excludeAttrs = Object.keys(ops.exclude)
        let treeData = []
        let dg = (data) =>{data.forEach((item,index)=>{
                excludeAttrs.every(attr=>{let attrs = attr.split('.')
                   let val = attrs.reduce(a=>{return item[a]
                   })
                   return item[attr] !== ops.exclude[attr]
                }) && treeData.push(item)

                item.children
            })
        }
        
    }

正文完
 0