简体   繁体   English

primeng下拉列表显示值不是选择标签

[英]primeng dropdown showing value not label on select

Using https://www.primefaces.org/primeng/#/dropdown the editable version of dropdown with filter 使用https://www.primefaces.org/primeng/#/dropdown可编辑的下拉列表与过滤器

I am seeing that choosing an option shows the value instead of the label when selected. 我看到选择一个选项会在选中时显示值而不是标签。

在此输入图像描述

code

<div class="col-md-5 col-xs-12"><p-dropdown [options]="metaAttributesOptions[n]" [filter]="true" editable="editable" [style]="{'width':'100%'}" *ngIf="metaAttributesOptions[n]" formControlName="value"></p-dropdown>



this.metaAttributesOptions.push(x.options.map(v => {
                            return {
                                label: v.name,
                                value: v.value
                            }
                        }));

Its because you are not having the label attribute which is expected by primeng Dropdown object's type SelectItem 这是因为你没有primeng Dropdown对象的类型SelectItem所期望的label属性

So you need to modify your json in format of the SelectItem by looping into entire object and creating a custom object of type SelectItem as below, 因此,您需要通过循环到整个对象并创建SelectItem类型的自定义对象来修改SelectItem格式的json,如下所示,

forEach(serviceData =>(data) {
let color: SelectItem = { 

      label : data.name,
      value : data.id
})

Issue is that you can't use 问题是你不能使用

editable="editable" 可编辑=“编辑”

Not sure why. 不知道为什么。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM