我想从函数中生成下拉列表(https://www.primefaces.org/primeng/#/dropdown(。
功能:
getSelectItemsByProperty(name: string): SelectItem[] {
let resArray : SelectItem[] =[];
this.detailService.getOptionsByProperty(name).subscribe(x => resArray = x.map(val => {
return {
label: val.name,
value: val.value
}
}));
console.log(resArray);
return resArray;
}
html:
<p-dropdown [options]="getSelectItemsByProperty(name)" formControlName="value"></p-dropdown>
问题是getSelectedItemsbyProperty被称为疯狂。它永远不会停止调用该功能。
目标我要实现的是在不将SelectItem数组作为控制中的控制的情况下流行下拉列表的能力。我希望下拉选项由FormControl名称生成,并且下拉列表的值应映射到FormControl值。
我的问题与您相同。我使用的是多选择,并且使用了 OnPanelShow 事件。为了初始化我的选项。
<p-multiSelect [options]="computedOptions" (onPanelShow)="onPanelShow()"></p-multiSelect>
然后在您的组件中:
export class MyComponent {
computedOptions: SelectItem[];
onPanelShow(name: string) {
let resArray : SelectItem[] =[];
this.detailService.getOptionsByProperty(name).subscribe(x => resArray = x.map(val => {
return {
label: val.name,
value: val.value
}
}));
this.computedOptions = resArray;
}
}
在下拉列表的情况下, OnPanelShow 事件不存在。但是,我想您应该对 onfocus 事件具有相同的行为。