【发布时间】:2021-07-22 19:04:34
【问题描述】:
我正在尝试在 Angular 中创建多个下拉菜单,并且需要每个下拉菜单都少显示一个选项。我已经做到了这一点,但现在我的下拉菜单总是用一个值初始化。 我有多个下拉菜单并尝试使用一个选项数组并根据这些选项生成我的数据。我事先也不知道我需要多少下拉菜单。 问题是我还需要一个用户有时不想选择值的空白值。
最好的尊重
【问题讨论】:
标签: angular primeng primeng-dropdowns
我正在尝试在 Angular 中创建多个下拉菜单,并且需要每个下拉菜单都少显示一个选项。我已经做到了这一点,但现在我的下拉菜单总是用一个值初始化。 我有多个下拉菜单并尝试使用一个选项数组并根据这些选项生成我的数据。我事先也不知道我需要多少下拉菜单。 问题是我还需要一个用户有时不想选择值的空白值。
最好的尊重
【问题讨论】:
标签: angular primeng primeng-dropdowns
我不完全确定您想要做什么,但这对您想要实现的目标有帮助吗?
getOptions(country: Country) {
let index = this.cities.findIndex(c => c.country === country);
return this.cities.slice(0,this.cities.length - index);
}
constructor() {
this.countries = [
{ name: 'USA' },
{ name: 'Italy' },
{ name: 'UK' },
{ name: 'Turkey' },
{ name: 'France' }
];
this.cities = [
{ name: 'New York', code: 'NY', country: this.countries[0] },
{ name: 'Rome', code: 'RM', country: this.countries[1] },
{ name: 'London', code: 'LDN', country: this.countries[2] },
{ name: 'Istanbul', code: 'IST', country: this.countries[3] },
{ name: 'Paris', code: 'PRS', country: this.countries[4] }
];
}
<p-dropdown [options]="getOptions(country)" [ngModel]="dataBind.get(country)" optionLabel="name"
(onFocus)="createCityOptions()" editable="true" optionLabel="name"></p-dropdown>
如果没有,您可以进一步描述您的意图,我很乐意更新答案。
您可能还想查看此StackBlitz。
【讨论】: