Skip to content

Commit

Permalink
fix: #136 修复树形懒加载时不反显的bug
Browse files Browse the repository at this point in the history
  • Loading branch information
greper committed Jan 12, 2021
1 parent 69b4ef1 commit ec08af0
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import * as Api from '@/business/modules/example/views/form/area/api'

export const crudOptions = {
options: {
height: '100%'
Expand Down Expand Up @@ -48,6 +50,41 @@ export const crudOptions = {
},
rules: [{ required: true, message: '请选择' }]
}
},
{
title: '树形懒加载',
key: 'tree5',
type: 'tree-selector',
dict: {
isTree: true,
label: 'name',
value: 'code',
getNodes (values) { // 配置行展示远程获取nodes
return Api.GetNodesByValues(values)
}
},
form: {
component: {
span: 24,
props: {
multiple: false,
elProps: {
lazy: true,
load (node, resolve) { // 懒加载
if (node.level === 0) {
Api.GetTreeChildrenByParentId().then(data => {
resolve(data)
})
return
}
Api.GetTreeChildrenByParentId(node.data.code).then(data => {
resolve(data)
})
}
}
}
}
}
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -183,16 +183,14 @@ export default {
// })
// },
onDictLoaded () {
log.debug('onDictLoaded')
log.debug('onDictLoaded', this.dict, this.value)
this.setValue(this.value)
},
setValue (value) {
log.debug('setValue:', this.currentValue, this.value, this._options)
if (this.currentValue === this.value) {
return
}
if (this._options == null || this._options.length === 0) {
return
}
let arrValue = value
if (value == null) {
this.selected = []
Expand All @@ -202,11 +200,15 @@ export default {
arrValue = [arrValue]
}
if (this.dict.getNodes) {
log.debug('getNodes:', arrValue)
this.dict.getNodes(arrValue).then(nodes => {
this.selectedNodes(nodes, value)
})
} else {
const nodes = []
if (this._options == null || this._options.length === 0) {
return
}
for (const item of arrValue) {
const data = this._options
const node = d2CrudPlus.util.dict.getByValue(item, data, this.dict)
Expand Down

0 comments on commit ec08af0

Please sign in to comment.