網(wǎng)站首頁 編程語言 正文
- 最近有個(gè)需求,懶加載樹形結(jié)構(gòu),默認(rèn)展開二級(jí)節(jié)點(diǎn)。試了獲取節(jié)點(diǎn)設(shè)置節(jié)點(diǎn)的expanded屬性,發(fā)現(xiàn)不生效
this.$refs.tree.store.nodesMap[data.id].expanded = true
- 看了下官方文檔利用default-expanded-keys屬性,懶加載第一級(jí)的時(shí)候?qū)⒌谝患?jí)節(jié)點(diǎn)的key放到定義的默認(rèn)展開數(shù)組即default-expanded-keys動(dòng)態(tài)綁定的數(shù)組就可以實(shí)現(xiàn)改工能
- 部分代碼入下圖
//css
<el-tree
ref="menuTree"
:props="defaultProps"
node-key="id"
:key="treeKey"
lazy
:default-expanded-keys="treeExpandelKeys"
:load="loadDeptNode"
:highlight-current="true"
@node-contextmenu="rightClick"
@node-expand="nodeExpand"
></el-tree>
//js
loadDeptNode(node, resolve, cb) {
this.resolve = resolve;
// 查詢參數(shù)
let reqData = {
roleTypeId: this.roleTypeId,
};
if (node.level === 0) {
this.rootNode = node;
this.rootNode_resolve = resolve; //同上,把node.level == 0的resolve也存起來
resolve([this.rootNodeData]);
this.treeExpandelKeys.push(this.rootNodeData.id)
this.fristNodeKeys.push(this.rootNodeData.id)
} else if (node.level > 0) {
// 向后臺(tái)發(fā)送查詢請(qǐng)求
getNodesService({ params: { node: node.data.id } })
.then((res) => {
// 請(qǐng)求成功,且查詢出有數(shù)據(jù)時(shí)
if (res && res.data) {
let resData = res.data || [];
var newN = [];
resData.forEach((it) => {
let newIt = Object.assign({}, it, {
leaf: it.leaf == "1" ? true : false,
});
newN.push(newIt);
});
if(node.level == 1){
this.secondNodeKeys = [];
newN.forEach(item=>{
this.secondNodeKeys.push(item.id)
})
}
resolve(newN);
}
// 請(qǐng)求失敗的情況,或者是查無數(shù)據(jù)的時(shí)候
else {
resolve([]);
}
})
.catch((e) => {
if (node.level === 0) {
resolve(treeData);
} else {
resolve([]);
}
});
}
},
原文鏈接:https://blog.csdn.net/organ_sweet/article/details/125450235
相關(guān)推薦
- 2023-02-12 Jupyter?Notebook讀取csv文件出現(xiàn)的問題及解決_python
- 2022-09-09 Nginx使用自簽ssl證書實(shí)現(xiàn)https連接的方法_nginx
- 2022-12-22 python3中超級(jí)好用的日志模塊-loguru模塊使用詳解_python
- 2022-07-24 Golang實(shí)現(xiàn)可重入鎖的示例代碼_Golang
- 2023-01-02 最新C語言中g(shù)etchar的使用_C 語言
- 2022-04-28 Python的命令行參數(shù)實(shí)例詳解_python
- 2022-02-16 瀏覽器斷點(diǎn)如何使用(測試工具)
- 2022-09-03 Python標(biāo)準(zhǔn)庫sys庫常用功能詳解_python
- 最近更新
-
- window11 系統(tǒng)安裝 yarn
- 超詳細(xì)win安裝深度學(xué)習(xí)環(huán)境2025年最新版(
- Linux 中運(yùn)行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲(chǔ)小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎(chǔ)操作-- 運(yùn)算符,流程控制 Flo
- 1. Int 和Integer 的區(qū)別,Jav
- spring @retryable不生效的一種
- Spring Security之認(rèn)證信息的處理
- Spring Security之認(rèn)證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權(quán)
- redisson分布式鎖中waittime的設(shè)
- maven:解決release錯(cuò)誤:Artif
- restTemplate使用總結(jié)
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實(shí)現(xiàn)加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務(wù)發(fā)現(xiàn)-Nac
- Spring Security之基于HttpR
- Redis 底層數(shù)據(jù)結(jié)構(gòu)-簡單動(dòng)態(tài)字符串(SD
- arthas操作spring被代理目標(biāo)對(duì)象命令
- Spring中的單例模式應(yīng)用詳解
- 聊聊消息隊(duì)列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠(yuǎn)程分支