fix: 增加或删除数据源,只有一条数据时操作完需要刷新页面才会更新

This commit is contained in:
taojinlong 2021-12-20 16:46:40 +08:00
parent 7052f9b945
commit 940147a687

View File

@ -140,14 +140,26 @@ export default {
let typeData = [] let typeData = []
listDatasourceByType(datasource.type).then(res => { listDatasourceByType(datasource.type).then(res => {
typeData = this.buildTree(res.data) typeData = this.buildTree(res.data)
for (let index = 0; index < this.tData.length; index++) { if(typeData.length === 0){
if (typeData[0].id === this.tData[index].id) { let index = this.tData.findIndex(item => {
this.tData[index].children = typeData[0].children if ( item.id === datasource.type) {
return true;
}
})
this.tData.splice(index,1)
}else {
let find = false;
for (let index = 0; index < this.tData.length; index++) {
if (typeData[0].id === this.tData[index].id) {
this.tData[index].children = typeData[0].children
find = true
}
}
if(!find){
this.tData.push(typeData[0])
} }
} }
}) })
}, },
buildTree(array) { buildTree(array) {
const types = {} const types = {}