【问题标题】:how to display object value of multiselect primeng angular2如何显示多选primeng angular2的对象值
【发布时间】:2017-08-18 13:20:00
【问题描述】:

我正在关注这个https://www.primefaces.org/primeng/#/multiselect,但文档只有关于打印字符串值的信息。如何显示对象值。 this.cities.push({label:'New York', value:{id:1, name: 'New York', cityCode: 'NY'}}); 例如我想显示代码。我试过 {{selectedCity.cityCode}} 它正在显示 [obj obj]

【问题讨论】:

    标签: angular primeng


    【解决方案1】:

    由于selectedCity 是一个数组,您应该使用*ngFor 来循环遍历项目。

    <div *ngFor="let city of selectedCities">
      <p>{{city.id}}. {{city.cityCode}} - {{city.name}}</p>
    </div>
    

    Plunker demo

    【讨论】:

    • 谢谢,但为什么我不能用它作为 {{ selectedCities.id }}
    • 因为selectedCities是一个数组,所以selectedCities中的对象有id,selectedCities本身没有任何属性/属性id
    • cities: SelectItem[]; selectedCity: any; this.cities = []; this.cities.push({label:'New York', value:{id:1, name: 'New York', code: 'NY'}}); {{selectedCity.id}} 我可以这样访问吗?或者没有 *ngFor 的替代方法?
    • 那你必须手动提供对象索引,比如{{selectedCity[0].id}}, {{selectedCity[1].id}}, {{selectedCity[2].id}}
    • 非常感谢,还有一个快速的问题,在 ngprime 的多选下拉列表中有搜索和全选选项,如果可以,我们可以删除它们吗? link
    猜你喜欢
    • 2021-08-08
    • 1970-01-01
    • 2021-01-25
    • 1970-01-01
    • 2016-11-24
    • 1970-01-01
    • 2016-08-28
    • 2017-04-20
    相关资源
    最近更新 更多