Skip to content

Commit

Permalink
Merge pull request #611 from DaoCloud/fix/select-search
Browse files Browse the repository at this point in the history
fix(select): fix the useless search method of select
  • Loading branch information
olivewind authored Oct 30, 2018
2 parents 26edb9a + 46feb3d commit 34e5008
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 21 deletions.
6 changes: 6 additions & 0 deletions examples/view/demos/select/demo-3.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
v-model="select"
placeholder="一个带搜索下拉框"
:with-search="true"
:search-method="search"
search-placeholder="搜索条件在这里">
<dao-option-group>
<dao-option
Expand Down Expand Up @@ -31,5 +32,10 @@
}]
};
},
methods: {
search(keyword, value) {
return value.indexOf(keyword) > -1;
},
},
};
</script>
4 changes: 2 additions & 2 deletions examples/view/page/components/select/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,8 @@
default: '-',
}, {
name: 'search-method',
type: 'String / Function',
desc: '搜索方法:若传入的是一个 string,则这个 string 需要是 option 中 value 的一个 key;若传入的是一个 function,则 function 接受的参数为 option 的 value 值,需返回 true 或 false',
type: 'Function',
desc: '搜索方法接受的参数为 option 的 value 值,需返回 true 或 false',
options: ['-'],
default: '-',
}, {
Expand Down
23 changes: 5 additions & 18 deletions src/components/dao-select/dao-option.vue
Original file line number Diff line number Diff line change
Expand Up @@ -36,25 +36,12 @@
// 绑定搜索事件
this.$on('search', (filter, filterMethod) => {
let content;
switch (typeof filterMethod) {
case 'string':
content = this.value[filterMethod];
if (!content) {
this.matchedFilter = false;
}
if (content && content.indexOf(filter) > -1) {
this.matchedFilter = true;
}
break;
case 'function':
this.matchedFilter = filterMethod(filter);
break;
default:
// 默认根据 label 来搜索
if (!filterMethod) {
this.matchedFilter = (this.label ? this.label.indexOf(filter) > -1 : true);
}
if (!filterMethod) {
this.matchedFilter = (this.label ? this.label.indexOf(filter) > -1 : true);
} else {
this.matchedFilter = filterMethod(filter);
}
// 默认根据 label 来搜索
// 这里往上层传搜索结果,不是一个很好的操作,执行太频繁了
this.dispatch('Option-group', 'search-result');
});
Expand Down
2 changes: 1 addition & 1 deletion src/components/dao-select/dao-select.vue
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
default: false,
},
searchPlaceholder: String,
searchMethod: [String, Function],
searchMethod: Function,
withTab: {
type: Boolean,
default: false,
Expand Down

0 comments on commit 34e5008

Please sign in to comment.