el-tree組件如何更新指點(diǎn)節(jié)點(diǎn)的數(shù)據(jù)和子節(jié)點(diǎn)數(shù)據(jù),
現(xiàn)象入上圖
1、左側(cè)樹組件,右側(cè)其他組件
2、左側(cè)樹采用異步加載,點(diǎn)擊左側(cè)的node,右側(cè)會ajax請求數(shù)據(jù)并渲染,渲染的是點(diǎn)擊node下面的文件夾及其他
3、右側(cè)的文件夾雙擊是進(jìn)入,對應(yīng)左側(cè)也要展開,右側(cè)文件夾編輯可以修改文件夾名稱,移動文件夾的路徑,還有刪除文件夾和新建文件夾的功能,需要左側(cè)樹結(jié)構(gòu)也對應(yīng)更新
樹結(jié)構(gòu)代碼
<el-tree class="teamtree"
:props="defaultProps"
:load="loadNodephoto"
lazy
v-if="phototreeshow"
@node-expand="expandHandle"
ref="phototree"
node-key="folderId"
:default-expanded-keys="defaultexpendphoto"
empty-text="數(shù)據(jù)為空"
:expand-on-click-node="false"
:highlight-current="true"
@node-click="handleNodeClick">
</el-tree>
展開方法
loadNodephoto(node, resolve) {
let res1 = [];
// 此處緩存了resolve方法,想通過這種方式來更新節(jié)點(diǎn)數(shù)據(jù)
this.tmpResolvephoto = resolve;
if ("level" in node) {
if (node.level === 0) {
return resolve([
{
folderId: 0,
folderName: "全部圖片",
parentFolderId: null,
path: "0:全部圖片",
leaf: false
}
]);
}
}
// 這個方法是請求ajax把數(shù)據(jù)返回
this.getTreeData(node.data.folderId).then(res => {
resolve(res);
});
},
// 右側(cè)進(jìn)入左側(cè)對應(yīng)展開
photoExpend(list) {
let ori = new Set(this.defaultexpendphoto);
let now = new Set(list);
let res = new Set([...ori, ...now]);
res = Array.from(res);
this.defaultexpendphoto = [];
this.defaultexpendphoto = res;
},
expandHandle(data,node,arg){
this.photoExpend([data.folderId])
},
/** 圖片樹重新獲取節(jié)點(diǎn)數(shù)據(jù)
* @type:1/2/3 1:當(dāng)前文件夾/父級/爺爺級
* @id:文件夾id
* @idtype:1/2:傳入的id是當(dāng)前/父級
*/
getPhotoNodeData(type, id, idtype) {
console.log(type, id, idtype)
let grandId, grandnode, parentnode, parentId, nownode;
// 爺級都需要傳父級id
if (type == 3 && idtype == 2) {
parentnode = this.$refs.phototree.getNode(id);
if (parentnode) {
grandId = parentnode.data.parentFolderId || 0;
console.log(grandId)
grandnode = this.$refs.phototree.getNode(grandId);
this.loadNodephoto(grandnode, this.tmpResolvephoto);
}
} else if (type == 2 && idtype == 2) {
parentnode = this.$refs.phototree.getNode(id);
if (parentnode) {
this.loadNodephoto(parentnode, this.tmpResolvephoto);
}
} else if (type == 2 && idtype == 1) {
// 父級傳入自己的id
nownode = this.$refs.phototree.getNode(id);
if (nownode) {
parentId = nownode.data.parentFolderId || 0;
this.photoExpend([parentId])
parentnode = this.$refs.phototree.getNode(parentId);
this.loadNodephoto(parentnode, this.tmpResolvephoto);
}
} else {
console.log(type, idtype);
}
}
目前想到的是通過緩存resolve方法,然后通過:load對應(yīng)的事件方法來重新加載數(shù)據(jù)。這樣發(fā)現(xiàn)了一個問題:
我現(xiàn)在改成了通過V-if每次修改完成之后都重新渲染tree,這樣實(shí)際上是有問題的,還請各位大佬給個正確的辦法 或者demo ,其實(shí)實(shí)現(xiàn)的功能類似于windows的文件管理器
聯(lián)系我:498755303@qq.comu
北大青鳥APTECH成立于1999年。依托北京大學(xué)優(yōu)質(zhì)雄厚的教育資源和背景,秉承“教育改變生活”的發(fā)展理念,致力于培養(yǎng)中國IT技能型緊缺人才,是大數(shù)據(jù)專業(yè)的國家
北大青鳥中博軟件學(xué)院創(chuàng)立于2003年,作為華東區(qū)著名互聯(lián)網(wǎng)學(xué)院和江蘇省首批服務(wù)外包人才培訓(xùn)基地,中博成功培育了近30000名軟件工程師走向高薪崗位,合作企業(yè)超4
中公教育集團(tuán)創(chuàng)建于1999年,經(jīng)過二十年潛心發(fā)展,已由一家北大畢業(yè)生自主創(chuàng)業(yè)的信息技術(shù)與教育服務(wù)機(jī)構(gòu),發(fā)展為教育服務(wù)業(yè)的綜合性企業(yè)集團(tuán),成為集合面授教學(xué)培訓(xùn)、網(wǎng)
達(dá)內(nèi)教育集團(tuán)成立于2002年,是一家由留學(xué)海歸創(chuàng)辦的高端職業(yè)教育培訓(xùn)機(jī)構(gòu),是中國一站式人才培養(yǎng)平臺、一站式人才輸送平臺。2014年4月3日在美國成功上市,融資1
曾工作于聯(lián)想擔(dān)任系統(tǒng)開發(fā)工程師,曾在博彥科技股份有限公司擔(dān)任項(xiàng)目經(jīng)理從事移動互聯(lián)網(wǎng)管理及研發(fā)工作,曾創(chuàng)辦藍(lán)懿科技有限責(zé)任公司從事總經(jīng)理職務(wù)負(fù)責(zé)iOS教學(xué)及管理工作。
浪潮集團(tuán)項(xiàng)目經(jīng)理。精通Java與.NET 技術(shù), 熟練的跨平臺面向?qū)ο箝_發(fā)經(jīng)驗(yàn),技術(shù)功底深厚。 授課風(fēng)格 授課風(fēng)格清新自然、條理清晰、主次分明、重點(diǎn)難點(diǎn)突出、引人入勝。
精通HTML5和CSS3;Javascript及主流js庫,具有快速界面開發(fā)的能力,對瀏覽器兼容性、前端性能優(yōu)化等有深入理解。精通網(wǎng)頁制作和網(wǎng)頁游戲開發(fā)。
具有10 年的Java 企業(yè)應(yīng)用開發(fā)經(jīng)驗(yàn)。曾經(jīng)歷任德國Software AG 技術(shù)顧問,美國Dachieve 系統(tǒng)架構(gòu)師,美國AngelEngineers Inc. 系統(tǒng)架構(gòu)師。