Merge pull request #6211 from msidolphin/fix/#6209

fix: 解决了checkbox-group多层嵌套数据相互干扰的问题
This commit is contained in:
debugIsFalse 2019-09-04 10:26:43 +08:00 committed by GitHub
commit 56ed584231
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 4 deletions

View file

@ -49,7 +49,7 @@
},
methods: {
updateModel (update) {
this.childrens = findComponentsDownward(this, 'Checkbox');
this.childrens = findComponentsDownward(this, 'Checkbox', 'CheckboxGroup');
if (this.childrens) {
const { value } = this;
this.childrens.forEach(child => {

View file

@ -212,11 +212,18 @@ export function findComponentDownward (context, componentName) {
}
// Find components downward
export function findComponentsDownward (context, componentName) {
export function findComponentsDownward (context, componentName, ignoreComponentNames = []) {
if (!Array.isArray(ignoreComponentNames)) {
ignoreComponentNames = [ignoreComponentNames]
}
return context.$children.reduce((components, child) => {
if (child.$options.name === componentName) components.push(child);
const foundChilds = findComponentsDownward(child, componentName);
return components.concat(foundChilds);
if (ignoreComponentNames.indexOf(child.$options.name) < 0) {
const foundChilds = findComponentsDownward(child, componentName);
return components.concat(foundChilds);
} else {
return components
}
}, []);
}