为一个输入实现多个自动完成

发布于 2025-01-11 04:45:20 字数 180 浏览 0 评论 0原文

我目前有一个具有自动完成功能的输入字段,我试图为每个输入的项目本质上进行两阶段自动完成,例如输入我将显示 IP 地址,选择在输入中输入“ipAddress=”,然后我会喜欢根据所选选项在同一输入中显示另一个自动完成以显示可用地址。然后他们会添加一个逗号并重复添加任何其他过滤器。我只是不确定这会被称为什么或如何实现它,所以任何提示或想法将不胜感激

I currently have an input field that has an autocomplete, I’m trying to have essentially a two stage autocomplete for each entered item, for example typing I would show IP Address, selecting that enters “ipAddress=“ into the input, I would then like to display another autocomplete in the same input based on the selected option to display the available addresses. Then they would add a comma and repeat to add any other filters. I just am not sure what this would be called or how to implement this so any tips or ideas would be greatly appreciated

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

述情 2025-01-18 04:45:20

尝试这样的事情:

TS:

itemList: any[] = [
  { name: "item1", IPForm: new FormControl(), AnotherListValue: [], AnotherForm: new FormControl() },
  { name: "item2", IPForm: new FormControl(), AnotherListValue: [], AnotherForm: new FormControl() }
];

// Fill my another value regarding to selected IP
onSelectedIP(selected: any, item: any) {
    this.myService.getListValue(selected.IP).subscribe(result => item.AnotherListValue = result);
}

HTML

<div *ngFor="let item of itemList">
    <mat-form-field>
        <input type="text" placeholder="Select IP" matInput [matAutocomplete]="itm" [formControl]="item.IPForm">
        <mat-autocomplete autoActiveFirstOption #itm="matAutocomplete" [displayWith]="displayFn" (optionSelected)="onSelectedIP($event.option.value, item)">
            <mat-option *ngFor="let option of IPList | async" [value]="option">
                {{option.IP}}
            </mat-option>
        </mat-autocomplete>
    </mat-form-field>
</div>

您只需要添加第二个自动完成等等

Try something like this:

TS:

itemList: any[] = [
  { name: "item1", IPForm: new FormControl(), AnotherListValue: [], AnotherForm: new FormControl() },
  { name: "item2", IPForm: new FormControl(), AnotherListValue: [], AnotherForm: new FormControl() }
];

// Fill my another value regarding to selected IP
onSelectedIP(selected: any, item: any) {
    this.myService.getListValue(selected.IP).subscribe(result => item.AnotherListValue = result);
}

HTML

<div *ngFor="let item of itemList">
    <mat-form-field>
        <input type="text" placeholder="Select IP" matInput [matAutocomplete]="itm" [formControl]="item.IPForm">
        <mat-autocomplete autoActiveFirstOption #itm="matAutocomplete" [displayWith]="displayFn" (optionSelected)="onSelectedIP($event.option.value, item)">
            <mat-option *ngFor="let option of IPList | async" [value]="option">
                {{option.IP}}
            </mat-option>
        </mat-autocomplete>
    </mat-form-field>
</div>

You just need to add second auto-complete and so on

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文