乐趣区

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

      

       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
            })
        }
        
    }
退出移动版