autocomplete 自动完成
autocomplete 自动完成
输入框自动完成功能。
数据源说明
静态
指获取后每一次筛选是通过 filterOption 过滤,数据来源于 asyncData、enum。
若 schema.format: 'email' 时自动渲染为自动补全邮箱后缀,默认 ['qq.com', '163.com', 'gmail.com', '126.com', 'aliyun.com'] 可通过 enum 来重新调整该值或全局配置 uiEmailSuffixes。
实时
指获取后每一次筛选是通过 filterOption 过滤,数据来源于 asyncData。
代码演示
基础样例
最简单的用法。
import { Component } from '@angular/core';import { SFSchema, SFAutoCompleteWidgetSchema } from '@delon/form';import { NzMessageService } from 'ng-zorro-antd/message';import { of } from 'rxjs';@Component({ selector: 'form-autocomplete-simple', template: `<sf [schema]="schema" (formSubmit)="submit($event)"></sf>`,})export class FormAutocompleteSimpleComponent { schema: SFSchema = { properties: { format: { type: 'string', title: 'Format', format: 'email', }, widget: { type: 'string', title: '指定widget', ui: { widget: 'autocomplete', type: 'email', } as SFAutoCompleteWidgetSchema, }, async: { type: 'string', title: '异步', ui: { widget: 'autocomplete', debounceTime: 100, asyncData: (input: string) => of(input ? [{ label: input, value: 1 }, { label: input + input, value: 2 }] : []), } as SFAutoCompleteWidgetSchema, }, }, }; constructor(public msg: NzMessageService) { } submit(value: any) { this.msg.success(JSON.stringify(value)); }}
API
schema 属性
| [enum] |
静态数据源 |
SFSchemaEnumType[] |
- |
|
|
|
|
| [readOnly] |
禁用状态 |
boolean |
- |
|
|
|
|
ui 属性
| [asyncData] |
实时数据源 |
(input: string) => Observable<SFSchemaEnumType[]> |
- |
|
|
|
|
| [size] |
大小,等同 nzSize |
string |
- |
|
|
|
|
| [placeholder] |
在文字框中显示提示讯息 |
string |
- |
|
|
|
|
| [filterOption] |
是否根据输入项进行筛选,默认只对 label 属性执行不区分大小定 indexOf 过滤。当其为一个函数时,会接收 inputValue option 两个参数,当 option 符合筛选条件时,应返回 true,反之则返回 false。 |
boolean or (inputValue: string, option: SFSchemaEnum) => boolean |
true |
|
|
|
|
| [type] |
模式,自动完成常见邮箱后缀,可以重新使用 enum 来指定新后缀 |
email |
- |
|
|
|
|
| [debounceTime] |
去抖时间,当实时数据源时默认最少 50,单位:毫秒 |
number |
0 |
|
|
|
|
| [defaultActiveFirstOption] |
是否默认高亮第一个选项 |
boolean |
true |
|
|
|
|
| [backfill] |
使用键盘选择选项的时候把选中项回填到输入框中 |
boolean |
false |
|
|
|
|
| [change] |
变更回调 |
(item: NzAutocompleteOptionComponent) => void |
- |
|
|
|
|
| [nzWidth] |
自定义宽度单位 px |
number |
触发元素宽度 |
|
|
|
|