1+ <template >
2+ <div class =" ldq-tree" >
3+ <search-node v-for =" item of deepData" :key =" item[nodeKey]" :index =" item[nodeKey]" :data =" item" ></search-node >
4+ </div >
5+ </template >
6+
17<script >
28import searchNode from ' ./search-node.vue'
39import { computSortNum , getSortData , getDictionary , deepCopy } from ' ./utils.js'
@@ -68,10 +74,7 @@ export default {
6874 }
6975 },
7076 filterNode: { // 过滤节点的方法
71- type: Function ,
72- default : function () {
73- return true
74- }
77+ type: Function
7578 }
7679 },
7780 data () {
@@ -102,15 +105,8 @@ export default {
102105 this .timer = setTimeout (_ => {
103106 if (val) return this .deepData = this ._getLdqTree (this .deepData )
104107 const keys = this .showCheckbox ? this .getCheckedKeys () : []
105- /**
106- * 这里必须先清空数据, 再进行赋值, 不然会产生严重的性能问题
107- * 很有可能是vue内部对多次赋值操作进行合并所产生的
108- */
109- this .deepData = []
110- this .$nextTick (_ => {
111- this .deepData = deepCopy (this .sourceData )
112- this .setCheckedByKeys (keys, true )
113- })
108+ this .deepData = deepCopy (this .sourceData )
109+ this .setCheckedByKeys (keys, true )
114110 }, this .searchDebounce )
115111 }
116112 },
@@ -122,11 +118,6 @@ export default {
122118 }
123119 this ._initData ()
124120 },
125- render () {
126- return < div class = " ldq-tree" >
127- { this .deepData .map (item => < search- node key= {item[this .nodeKey ]} data= {item}>< / search- node> ) }
128- < / div>
129- },
130121 methods: {
131122 /**
132123 * 前序迭代所有节点
@@ -152,7 +143,7 @@ export default {
152143 _levelOrder (nodes , callback ) {
153144 if (! nodes .length ) return null
154145 const { children } = this .defaultProps
155- let queue = [... nodes], res = []
146+ let queue = [... nodes]
156147 while (queue .length ) {
157148 let len = queue .length
158149 while (len-- ) {
@@ -211,7 +202,7 @@ export default {
211202 // 子节点是否全选 || 子节点的叶子节点全部选中
212203 parent .checked = checkedNum === arr .length || ! this ._levelOrder (arr, item => ! item .checked )
213204 // 子节点有一个是半选 || 被选中的节点不为零并且被选中的节点不等于子节点长度 || 该节点不是全选并且子节点中任意一个被选中
214- parent .indeterminate = anyOne || (!! checkedNum && checkedNum != arr .length ) || (! parent .checked && !! this ._preorder (arr, item => item .checked ))
205+ parent .indeterminate = anyOne || (!! checkedNum && checkedNum !== arr .length ) || (! parent .checked && !! this ._preorder (arr, item => item .checked ))
215206 }
216207 }
217208 dfs (this .sourceData )
0 commit comments