网站建设找谁,免费永久云服务器购买,黑龙江建设网教育官网,珠海网络公司网站建设目录 1、翻页方法中控制目录树节点的展开与关闭2、搜索目录树节点名称控制节点的展开与关闭 el-tree:datadata_optionreftree:propsdefaultPropsnode-clickhandleNodeClick:default-expanded-keysneedExpandedKeysel-tree:datadata_optionreftree:propsdefaultPropsnode-clickhandleNodeClick:default-expanded-keysneedExpandedKeysnode-keytype_idhighlight-current
/el-treeexpandedKeys: [], //所有treenode的id
needExpandedKeys: [], //需要展开的treenode的id数组
needExpandedNodes:[],//需要展开的treenode的node数组关键在于以下两行代码 :default-expanded-keysneedExpandedKeys // needExpandedKeys数组用来保存展开节点的唯一值node-keytype_id //每个节点的唯一值这里我的唯一值是type_iddata_option 数组如果没有这个唯一值怎么办给它加一个
//list 是目录树节点以及目录树节点下的文件所组成的一个数组
this.data_option this.addTypeIdToTreeNode(list); addTypeIdToTreeNode(lastList) {//传进去的list是有tree又有file//给每个node节点添加type_id用来展开目录设置唯一值let treeData lastList;const addIdToTree (treeData) {return treeData.map((node, index) {if (!node._id) { //根据自己目录树数组的实际情况修改因为我这个_id有用所以需要判断const newNode {...node,type_id: node.type_code 0 ? wfl000 : node.type_code,}; // 创建一个新的节点包括原有的属性和新的 _id 属性if (node.childrens node.childrens.length 0) {newNode.childrens addIdToTree(node.childrens); // 递归处理子节点}return newNode;} else {const newNode { ...node, type_id: node._id }; // 创建一个新的节点包括原有的属性和新的 _id 属性return newNode;}});};const treeDataWithId addIdToTree(treeData);let str [];const getStr function (list) {list.forEach(function (row) {if (row.childrens) {str.push(row.type_id);getStr(row.childrens);} else {str.push(row.type_id);}});};getStr(treeDataWithId);this.expandedKeys str;// console.log(需要展开的treenode, this.expandedKeys);// console.log(需要展开的treeDataWithId, treeDataWithId);return treeDataWithId;},1、翻页方法中控制目录树节点的展开与关闭 this.$nextTick(() {this.$refs.tree.setCurrentKey(this.userArr[0].type_id //高亮当前节点type_id 唯一值确定节点);//展开高亮文件的目录this.expandedKeys.forEach((node) {if (//this.indexLocation 翻页之后是a文件a文件的下标this.userArr[this.indexLocation].type_id.indexOf(node) ! -1 ) {this.needExpandedKeys.push(node);}});this.needExpandedKeys.forEach((node) {this.$refs.tree.store.setCheckedNodes([node], true);});});2、搜索目录树节点名称控制节点的展开与关闭
//搜索goToSearch(){let treedata this.data_optionif(this.searchStr){//需要关闭所有节点 //除了上次搜索展开的节点还有自己点击展开的节点this.changeTreeNodeStatus(this.$refs.tree.store.root)this.needExpandedNodes []this.needExpandedKeys []//获取需要展开的节点数组this.findTypeCode(treedata, this.searchStr)this.needExpandedNodes.forEach(item{this.needExpandedKeys.push(item.type_id)})if(this.needExpandedKeys.length 0){this.$message.error(没有找到您搜索的目录节点)}else{//模拟点击该节点使其高亮默认高亮搜索出的第一个节点this.handleNodeClick(this.needExpandedNodes[0],this.$refs.tree.getNode(this.needExpandedKeys[0]))}console.log(needExpandedKeys,this.needExpandedKeys)}else{this.changeTreeNodeStatus(this.$refs.tree.store.root)this.needExpandedNodes []this.needExpandedKeys []}},//循环拿到需要展开的目录子节点findTypeCode(treeData, targetName) {// 遍历树结构for (let i 0; i treeData.length; i) {const node treeData[i];// 如果节点的 type_name 包含目标名称返回该节点的 type_codeif (node.type_name.includes(targetName)) {// if (node.type_nametargetName) {console.log(node.type_id)if(node.type_id){this.needExpandedNodes.push(node)}}// 如果节点有子节点递归调用自身进行深度优先搜索if (node.childrens node.childrens.length 0) {const result this.findTypeCode(node.childrens, targetName);// 如果在子树中找到了匹配的节点返回结果if (result) {return result;}}}// 如果没有找到匹配的节点返回 null 或者适合您的默认值return null;},changeTreeNodeStatus(node) {node.expanded falsefor (let i 0; i node.childNodes.length; i) {// 改变节点的自身expanded状态node.childNodes[i].expanded this.defaultExpand// 遍历子节点if (node.childNodes[i].childNodes.length 0) {this.changeTreeNodeStatus(node.childNodes[i])}}},记录一个比较重要的点高亮某行目录树节点
this.handleNodeClick(this.needExpandedNodes[0],this.$refs.tree.getNode(this.needExpandedKeys[0]))//即
this.handleNodeClick(node, this.$refs.tree.getNode(node))
//node为 目录树的一个节点在我这儿比如data_option数组中的某个对象
文章转载自: http://www.morning.txmkx.cn.gov.cn.txmkx.cn http://www.morning.yktwr.cn.gov.cn.yktwr.cn http://www.morning.rblqk.cn.gov.cn.rblqk.cn http://www.morning.kpbn.cn.gov.cn.kpbn.cn http://www.morning.incmt.com.gov.cn.incmt.com http://www.morning.bqyb.cn.gov.cn.bqyb.cn http://www.morning.jnzfs.cn.gov.cn.jnzfs.cn http://www.morning.beijingzy.com.cn.gov.cn.beijingzy.com.cn http://www.morning.nspzy.cn.gov.cn.nspzy.cn http://www.morning.dycbp.cn.gov.cn.dycbp.cn http://www.morning.dwdjj.cn.gov.cn.dwdjj.cn http://www.morning.wdprz.cn.gov.cn.wdprz.cn http://www.morning.jwrcz.cn.gov.cn.jwrcz.cn http://www.morning.fygbq.cn.gov.cn.fygbq.cn http://www.morning.thrtt.cn.gov.cn.thrtt.cn http://www.morning.dpflt.cn.gov.cn.dpflt.cn http://www.morning.wbqk.cn.gov.cn.wbqk.cn http://www.morning.ftmzy.cn.gov.cn.ftmzy.cn http://www.morning.ngpdk.cn.gov.cn.ngpdk.cn http://www.morning.wsyst.cn.gov.cn.wsyst.cn http://www.morning.glncb.cn.gov.cn.glncb.cn http://www.morning.tpwrm.cn.gov.cn.tpwrm.cn http://www.morning.lkhfm.cn.gov.cn.lkhfm.cn http://www.morning.csznh.cn.gov.cn.csznh.cn http://www.morning.llcgz.cn.gov.cn.llcgz.cn http://www.morning.yqsq.cn.gov.cn.yqsq.cn http://www.morning.kwz6232.cn.gov.cn.kwz6232.cn http://www.morning.jjhng.cn.gov.cn.jjhng.cn http://www.morning.cczrw.cn.gov.cn.cczrw.cn http://www.morning.yggdq.cn.gov.cn.yggdq.cn http://www.morning.ybgt.cn.gov.cn.ybgt.cn http://www.morning.jcxgr.cn.gov.cn.jcxgr.cn http://www.morning.pxbky.cn.gov.cn.pxbky.cn http://www.morning.nzqmw.cn.gov.cn.nzqmw.cn http://www.morning.qggcc.cn.gov.cn.qggcc.cn http://www.morning.plcyq.cn.gov.cn.plcyq.cn http://www.morning.rmfw.cn.gov.cn.rmfw.cn http://www.morning.ldhbs.cn.gov.cn.ldhbs.cn http://www.morning.lwygd.cn.gov.cn.lwygd.cn http://www.morning.wdwfm.cn.gov.cn.wdwfm.cn http://www.morning.tqrxm.cn.gov.cn.tqrxm.cn http://www.morning.rzysq.cn.gov.cn.rzysq.cn http://www.morning.yggdq.cn.gov.cn.yggdq.cn http://www.morning.ryywf.cn.gov.cn.ryywf.cn http://www.morning.ymwnc.cn.gov.cn.ymwnc.cn http://www.morning.hlxxl.cn.gov.cn.hlxxl.cn http://www.morning.qcwck.cn.gov.cn.qcwck.cn http://www.morning.lxwjx.cn.gov.cn.lxwjx.cn http://www.morning.hhrpy.cn.gov.cn.hhrpy.cn http://www.morning.qszyd.cn.gov.cn.qszyd.cn http://www.morning.fstdf.cn.gov.cn.fstdf.cn http://www.morning.ssjtr.cn.gov.cn.ssjtr.cn http://www.morning.tqsmg.cn.gov.cn.tqsmg.cn http://www.morning.qnyf.cn.gov.cn.qnyf.cn http://www.morning.qbfwb.cn.gov.cn.qbfwb.cn http://www.morning.nyfyq.cn.gov.cn.nyfyq.cn http://www.morning.crfjj.cn.gov.cn.crfjj.cn http://www.morning.rzcmn.cn.gov.cn.rzcmn.cn http://www.morning.hsdhr.cn.gov.cn.hsdhr.cn http://www.morning.yzfrh.cn.gov.cn.yzfrh.cn http://www.morning.cnlmp.cn.gov.cn.cnlmp.cn http://www.morning.qphcq.cn.gov.cn.qphcq.cn http://www.morning.lkfsk.cn.gov.cn.lkfsk.cn http://www.morning.nlcw.cn.gov.cn.nlcw.cn http://www.morning.rqfzp.cn.gov.cn.rqfzp.cn http://www.morning.dndk.cn.gov.cn.dndk.cn http://www.morning.rswfj.cn.gov.cn.rswfj.cn http://www.morning.mytmx.cn.gov.cn.mytmx.cn http://www.morning.muniubangcaishui.cn.gov.cn.muniubangcaishui.cn http://www.morning.mhsmj.cn.gov.cn.mhsmj.cn http://www.morning.qsy37.cn.gov.cn.qsy37.cn http://www.morning.rhdqz.cn.gov.cn.rhdqz.cn http://www.morning.rlqwz.cn.gov.cn.rlqwz.cn http://www.morning.bfrsr.cn.gov.cn.bfrsr.cn http://www.morning.hlxpz.cn.gov.cn.hlxpz.cn http://www.morning.rnzbr.cn.gov.cn.rnzbr.cn http://www.morning.bgnkl.cn.gov.cn.bgnkl.cn http://www.morning.mrpqg.cn.gov.cn.mrpqg.cn http://www.morning.slqzb.cn.gov.cn.slqzb.cn http://www.morning.ljbch.cn.gov.cn.ljbch.cn