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

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

View File

@ -87,13 +87,33 @@ class Framework extends Component{
} }
exchangeValue(arr, dataObj = this.state.dataObj){ 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 list = arr.map(sel => typeof sel === 'object' ? { ...sel, __node: {} } : dataObj[sel]).filter(a => a)
let filterGroup = true, { tree, cascader } = this.props; let cgList = [ ...list ]
if(tree.show && tree.strict === false || cascader.show && cascader.strict === false){
filterGroup = false; 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){ value(sels, show, listenOn, jsChangeData){
@ -111,19 +131,19 @@ class Framework extends Component{
if(tree.show && tree.strict || cascader.show && cascader.strict){ if(tree.show && tree.strict || cascader.show && cascader.strict){
let data = this.state.data; let data = this.state.data;
this.clearAndReset(data, changeData); this.clearAndReset(data, changeData, false);
changeData = this.init({ data, prop }, true); changeData = this.init({ data, prop }, true);
} }
this.resetSelectValue(changeData, jsChangeData ? jsChangeData : changeData, true, listenOn); this.resetSelectValue(changeData, jsChangeData ? jsChangeData : changeData, true, listenOn);
this.setState({ show }) this.setState({ show })
} }
clearAndReset(data, changeData){ clearAndReset(data, changeData, parentCK){
const { selected, children, value } = this.props.prop; const { selected, children, value } = this.props.prop;
data.forEach(item => { 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]; let child = item[children];
child && isArray(child) && this.clearAndReset(child, changeData) child && isArray(child) && this.clearAndReset(child, changeData, item[selected])
}) })
} }