Commit fd7342bd authored by Liril's avatar Liril Committed by 杨奕

Cascader: Add before-filter hook

parent d3383729
...@@ -1656,6 +1656,7 @@ Search and select options with a keyword. ...@@ -1656,6 +1656,7 @@ Search and select options with a keyword.
| value | specify which key of option object is used as the option's value | string | — | — | | value | specify which key of option object is used as the option's value | string | — | — |
| children | specify which key of option object is used as the option's child options | string | — | — | | children | specify which key of option object is used as the option's child options | string | — | — |
| disabled | specify which key of option object indicates if the option is disabled | string | — | — | | disabled | specify which key of option object indicates if the option is disabled | string | — | — |
| before-filter | hook function before filtering with the value to be filtered as its parameter. If `false` or a `Promise` is returned, filtering will be aborted | function(value) | — | — |
### Events ### Events
| Event Name | Description | Parameters | | Event Name | Description | Parameters |
......
...@@ -1687,6 +1687,7 @@ ...@@ -1687,6 +1687,7 @@
| label | 指定选项标签为选项对象的某个属性值 | string | — | — | | label | 指定选项标签为选项对象的某个属性值 | string | — | — |
| children | 指定选项的子选项为选项对象的某个属性值 | string | — | — | | children | 指定选项的子选项为选项对象的某个属性值 | string | — | — |
| disabled | 指定选项的禁用为选项对象的某个属性值 | string | — | — | | disabled | 指定选项的禁用为选项对象的某个属性值 | string | — | — |
| before-filter | 可选参数, 筛选之前的钩子,参数为输入的值,若返回 false 或者 Promise 则停止筛选。 | function(value) | — | — |
### Events ### Events
| 事件名称 | 说明 | 回调参数 | | 事件名称 | 说明 | 回调参数 |
......
...@@ -139,6 +139,10 @@ export default { ...@@ -139,6 +139,10 @@ export default {
debounce: { debounce: {
type: Number, type: Number,
default: 300 default: 300
},
beforeFilter: {
type: Function,
default: null
} }
}, },
...@@ -328,8 +332,27 @@ export default { ...@@ -328,8 +332,27 @@ export default {
created() { created() {
this.debouncedInputChange = debounce(this.debounce, value => { this.debouncedInputChange = debounce(this.debounce, value => {
const before = this.beforeFilter(value);
if (before && before.then) {
this.menu.options = [{
__IS__FLAT__OPTIONS: true,
label: this.t('el.cascader.loading'),
value: '',
disabled: true
}];
before
.then(() => {
this.$nextTick(() => {
this.handleInputChange(value); this.handleInputChange(value);
}); });
});
} else if (before !== false) {
this.$nextTick(() => {
this.handleInputChange(value);
});
}
});
}, },
mounted() { mounted() {
......
...@@ -62,6 +62,7 @@ export default { ...@@ -62,6 +62,7 @@ export default {
}, },
cascader: { cascader: {
noMatch: 'No matching data', noMatch: 'No matching data',
loading: 'Loading',
placeholder: 'Select' placeholder: 'Select'
}, },
pagination: { pagination: {
......
...@@ -62,6 +62,7 @@ export default { ...@@ -62,6 +62,7 @@ export default {
}, },
cascader: { cascader: {
noMatch: '无匹配数据', noMatch: '无匹配数据',
loading: '加载中',
placeholder: '请选择' placeholder: '请选择'
}, },
pagination: { pagination: {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment