【el-tree】The difference between getCheckedKeys and getHalfCheckedKeys

When I changed the bug, I found that I was not very clear about the difference between the two

See the description on the official website

insert image description here
Although what I said seems to be quite clear, each word can be read separately, but I can’t understand it together

After I print the test myself, I believe I can understand it by combining the picture + text.
Add a ref to the el-tree, for example: ref="menu" Get the selected node array through this.$refs.menu.getCheckedKeys()

Let’s talk about getCheckedKeys() first. What it gets is the selected node. If all the child nodes are selected, then its upper level is in the ticked state, indicating that all items are selected. If the child nodes are not all selected, then Its upper level is the state of the horizontal bar, so at this time getCheckedKeys gets all the ticked nodes

As shown in the figure below, the length of the node array obtained by getCheckedKeys is 10
insert image description here


Then say getHalfCheckedKeys(), the same as above, add a ref to the el-tree, for example: ref="menu" Get the half-node node array through this.$refs.menu.getHalfCheckedKeys(), pay attention to this place, if the above The picture is
an example. Will this half node be an array of all checked nodes when the parent node is in the state of the bar? The answer is no, it refers to the number of the parent node in the
state of the bar.

As shown in the figure below, the length of the node array obtained by getHalfCheckedKeys is 2

insert image description here

Guess you like

Origin blog.csdn.net/weixin_49668076/article/details/129445770