2017-05-08 86 views
3

如何通過多選primeng的默認值來選擇,需要這個形式更新如何默認多選primeng的選擇值與顯示標註

代碼:

@Component({ 
    template: `<p-multiSelect [options]="cities" [(ngModel)]="selectedCities" ></p-multiSelect>` 
}) 
export class MyComponent { 

    cities: SelectItem[]; 
    selectedCities= []; 


    public constructor() { 
     this.cities = []; 
    this.cities.push({ label: 'Paris', value:{id:'1',country:'France', name:'paris'} }); 
    this.cities.push({ label: 'Madrid', value:{id:'2',country:'Spain', name:'madrid'} }); 
    this.selectedCities.push({id:'2',country:'Spain', name:'madrid'}) 
    } 

當前行爲:其值在salected列表中,但標籤有一個空

回答

0

Yo've添加optionLabel="name"您對多重選擇的元素:

<p-multiSelect [options]="cities" [(ngModel)]="selectedCities" optionLabel="name"></p-multiSelect>