fix: 解决了checkbox-group多层嵌套数据相互干扰的问题
This commit is contained in:
parent
630bc69d97
commit
67ddfcb7ed
2 changed files with 11 additions and 4 deletions
|
@ -49,7 +49,7 @@
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
updateModel (update) {
|
updateModel (update) {
|
||||||
this.childrens = findComponentsDownward(this, 'Checkbox');
|
this.childrens = findComponentsDownward(this, 'Checkbox', 'CheckboxGroup');
|
||||||
if (this.childrens) {
|
if (this.childrens) {
|
||||||
const { value } = this;
|
const { value } = this;
|
||||||
this.childrens.forEach(child => {
|
this.childrens.forEach(child => {
|
||||||
|
|
|
@ -212,11 +212,18 @@ export function findComponentDownward (context, componentName) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find components downward
|
// Find components downward
|
||||||
export function findComponentsDownward (context, componentName) {
|
export function findComponentsDownward (context, componentName, ignoreComponetNames = []) {
|
||||||
|
if (!Array.isArray(ignoreComponetNames)) {
|
||||||
|
ignoreComponetNames = [ignoreComponetNames]
|
||||||
|
}
|
||||||
return context.$children.reduce((components, child) => {
|
return context.$children.reduce((components, child) => {
|
||||||
if (child.$options.name === componentName) components.push(child);
|
if (child.$options.name === componentName) components.push(child);
|
||||||
|
if (ignoreComponetNames.indexOf(child.$options.name) < 0) {
|
||||||
const foundChilds = findComponentsDownward(child, componentName);
|
const foundChilds = findComponentsDownward(child, componentName);
|
||||||
return components.concat(foundChilds);
|
return components.concat(foundChilds);
|
||||||
|
} else {
|
||||||
|
return components
|
||||||
|
}
|
||||||
}, []);
|
}, []);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue