Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cascader: fix display errors #15935

Merged
merged 1 commit into from
Jul 24, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions packages/cascader-panel/src/store.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Node from './node';
import { coerceTruthyValueToArray } from 'element-ui/src/utils/util';
import { coerceTruthyValueToArray, valueEquals } from 'element-ui/src/utils/util';

const flatNodes = (data, leafOnly) => {
return data.reduce((res, node) => {
Expand Down Expand Up @@ -52,9 +52,8 @@ export default class Store {

getNodeByValue(value) {
if (value) {
value = Array.isArray(value) ? value[value.length - 1] : value;
const nodes = this.getFlattedNodes(false, !this.config.lazy)
.filter(node => node.value === value);
.filter(node => (valueEquals(node.path, value) || node.value === value));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

如果 value 是数组 这里是不是就报错了?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不会报错,valueEquals 就是为了比较 value 是数组的情况

return nodes && nodes.length ? nodes[0] : null;
}
return null;
Expand Down