修改直接设置父节点无法选中的问题

This commit is contained in:
maplemei 2020-12-01 18:08:03 +08:00
parent 7d4c53afba
commit 4c9baac4b3
4 changed files with 36 additions and 13 deletions

2
dist/static/2.js vendored

File diff suppressed because one or more lines are too long

2
dist/xm-select.js vendored

File diff suppressed because one or more lines are too long

View File

@ -18,7 +18,9 @@ var demo1 = xmSelect.render({
simple: true,
clickExpand: false,
clickCheck: false,
strict: false
},
radio: true,
toolbar: {
show: true,
list: ['ALL', 'REVERSE', 'CLEAR']
@ -48,6 +50,7 @@ var demo1 = xmSelect.render({
select: '',
unselect: '',
half: '',
parent: 'hidden',
},
})

View File

@ -87,13 +87,33 @@ class Framework extends Component{
}
exchangeValue(arr, dataObj = this.state.dataObj){
let { prop, tree, cascader, data } = this.props;
const { children, value } = prop;
let list = arr.map(sel => typeof sel === 'object' ? { ...sel, __node: {} } : dataObj[sel]).filter(a => a)
let filterGroup = true, { tree, cascader } = this.props;
if(tree.show && tree.strict === false || cascader.show && cascader.strict === false){
filterGroup = false;
let cgList = [ ...list ]
if(tree.show && tree.strict || cascader.show && cascader.strict){//严格模式
//向下递归, 找到所有的子节点
const addChild = (ls, parent) => {
let childs = parent[children]
if(childs && isArray(childs)){
childs.forEach(child => {
if(list.findIndex(l => l[value] === child[value]) === -1){
ls.push(child);
}
addChild(ls, child);
})
}
}
const firstParent = {}
firstParent[children] = list;
addChild(cgList, firstParent)
cgList = cgList.filter(item => item[this.props.prop.optgroup] !== true)
}
filterGroup && (list = list.filter(item => item[this.props.prop.optgroup] !== true))
return list;
return cgList;
}
value(sels, show, listenOn, jsChangeData){
@ -111,19 +131,19 @@ class Framework extends Component{
if(tree.show && tree.strict || cascader.show && cascader.strict){
let data = this.state.data;
this.clearAndReset(data, changeData);
this.clearAndReset(data, changeData, false);
changeData = this.init({ data, prop }, true);
}
this.resetSelectValue(changeData, jsChangeData ? jsChangeData : changeData, true, listenOn);
this.setState({ show })
}
clearAndReset(data, changeData){
clearAndReset(data, changeData, parentCK){
const { selected, children, value } = this.props.prop;
data.forEach(item => {
item[selected] = changeData.findIndex(c => c[value] === item[value]) != -1;
item[selected] = changeData.findIndex(c => c[value] === item[value]) != -1 || parentCK;
let child = item[children];
child && isArray(child) && this.clearAndReset(child, changeData)
child && isArray(child) && this.clearAndReset(child, changeData, item[selected])
})
}