el-tree 实现过滤之后,得到过滤后的数据


  
  
    获取当前node数据
  

filterNode(value, data) {
			if (!value) return true
			const val = value.toLowerCase()
			return data.name.toLowerCase().indexOf(val) !== -1
		},
setCurrentData() {
            const traverseNode = (node)=> {
                if (Object.prototype.toString.call(node) === '[object Array]') {
                    return node.map(t => traverseNode(t))
                }
                const data = {id: node.key, name: node.label, visible: node.visible, children: []}
                const childNodes = node.childNodes
                childNodes.forEach((child) => {
                    const item = traverseNode(child)
                    if (item.visible) {
                    data.visible = true
                    }
                    data.children.push(item)
                })
                return data
            }
            const traverseVisible = (arr)=> {
                return arr.filter(t => {
                    let visible = t.visible
                        if (!visible) {
                            return false
                        }
                        if (t.children) {
                            t.children = traverseVisible(t.children)
                        }
                        delete t.visible
                        return visible
                    })
            }
            const data = traverseNode(this.$refs.tree.store.root.childNodes)
            this.current = traverseVisible(data)
        }

你可能感兴趣的:(javascript,前端,vue.js)