export function preOrderTraversal(nodes, callback = () => { }) {
// 先确保传入数据数组 if (!Array.isArray(nodes)) return for (const node of nodes) { const ret = callback(node) if (ret === false) { break } else if (ret === true) { continue } node?.children?.length && preOrderTraversal(node.children, callback) } }
使用方法:
preOrderTraversal(cols, col => { // TODO ... })
标签:node,遍历,preOrderTraversal,ret,callback,先序,nodes,children From: https://www.cnblogs.com/cdyun/p/17168819.html