The use of information acquisition sub-element-ui tree node Select parent node

Use el-tree to show the organization's information and then passes it to the background as a query. The original version is all the selected nodes are passed to the back-end, back-end use in a way to query the data. This presents a problem if the root node is selected, it will put the whole tree data is passed to the back end, poor sql execution performance.

Back-end request, if the child node is selected, do not pass a child node, the information as long as the parent node spread out. Dog-eared element-ui documents, did not find ready-made method. Only to write a specific code is as follows (refer to the element-ui tree source)

getSimpleCheckedNodes(store) {
	const checkedNodes = [];
	const traverse = function(node) {
		const childNodes = node.root ? node.root.childNodes : node.childNodes;
	
		childNodes.forEach(child => {
			if (child.checked) {
				checkedNodes.push(child.data);
			}
			if (child.indeterminate) {
				traverse(child);
			}
		});
	};
	traverse(store)
	return checkedNodes;
}

....
// 调用
getSimpleCheckedNodes(this.$refs.tree.store);// el-tree的ref是tree

Hoping to help a friend in need, please be useful praise, hee hee :)

Published 53 original articles · won praise 39 · views 80000 +

Guess you like

Origin blog.csdn.net/Chinese521/article/details/98179487