修复setValue自定义数据时 操作报错

This commit is contained in:
maplemei 2019-12-04 13:21:56 +08:00
parent c6a5080161
commit 54a7bc73fd
4 changed files with 22 additions and 34 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

@ -3,6 +3,7 @@
:::demo :::demo
```html ```html
<div id="demo1" class="xm-select-demo"></div> <div id="demo1" class="xm-select-demo"></div>
<button class="layui-btn layui-btn-xs">sdf</button>
<script> <script>
var demo1 = xmSelect.render({ var demo1 = xmSelect.render({
@ -10,17 +11,31 @@ var demo1 = xmSelect.render({
autoRow: true, autoRow: true,
paging: true, paging: true,
pageSize: 2, pageSize: 2,
size:'mini',
tree: { tree: {
strict: false, strict: true,
show: true, show: true,
showFolderIcon: true, showFolderIcon: true,
showLine: true, showLine: true,
indent: 20, indent: 20,
expandedKeys: [ -1, -2 ], expandedKeys: [ -1, -2 ],
lazy: true,
load: function(item, cb){
setTimeout(function(){
if(item.name.endsWith('2')){
return cb([]);
}
cb([
{name: item.name + 1, value: item.value + '1', children: [] },
{name: item.name + 2, value: item.value + '2', children: [] },
])
}, 500)
}
}, },
model: { model: {
icon: 'hidden' icon: 'show'
}, },
radio: true,
toolbar: { toolbar: {
show: true show: true
}, },
@ -28,7 +43,7 @@ var demo1 = xmSelect.render({
data(){ data(){
return [ return [
{name: '北京市时代峰峻莱克斯顿荆防颗粒受到了开发建设的路口附近', value: -1, children: [ {name: '北京市时代峰峻莱克斯顿荆防颗粒受到了开发建设的路口附近', value: -1, children: [
{name: '朝阳区', value: 1}, {name: '朝阳区', value: 1, children: []},
{name: '海淀区', value: 2}, {name: '海淀区', value: 2},
{name: '通州区', value: 3}, {name: '通州区', value: 3},
]}, ]},
@ -40,33 +55,6 @@ var demo1 = xmSelect.render({
] ]
}, },
on: function(data){ on: function(data){
var arr = data.arr;
var item = data.change[0];
var isAdd = data.isAdd;
if(isAdd){
//检查是否有父节点
var parent = item.__node.parent;
if(parent){//有父节点,选中的是子节点,移除父节点的选中状态
var index = arr.findIndex(function(option){
return option.value === parent.value
})
if(index != -1){
arr.splice(index, 1)
}
}else{//无父节点,选中的是父节点,移除子节点的选中状态
var child = item.children;
child.forEach(function(childItem){
var index = arr.findIndex(function(option){
return option.value === childItem.value
})
if(index != -1){
arr.splice(index, 1)
}
})
}
return arr;
}
} }
}) })
</script> </script>

View File

@ -55,7 +55,7 @@ class Framework extends Component{
} }
exchangeValue(arr, dataObj = this.state.dataObj){ exchangeValue(arr, dataObj = this.state.dataObj){
let list = arr.map(sel => typeof sel === 'object' ? sel : dataObj[sel]).filter(a => a) let list = arr.map(sel => typeof sel === 'object' ? { ...sel, __node: {} } : dataObj[sel]).filter(a => a)
let filterGroup = true, { tree } = this.props; let filterGroup = true, { tree } = this.props;
if(tree.show && tree.strict === false){ if(tree.show && tree.strict === false){
filterGroup = false; filterGroup = false;