我正在使用angular2-multiselect-dropdown绑定服务器中的值
interface PayerDummyObjType{
id: string;
itemName: string;
}
PayerDummyObjType: PayerDummyObjType[];
PayerDummyObjTypeSelected: PayerDummyObjType[];
dropdownSettings = {};
this.http.getPBMPayerDetails().subscribe((data: FilterDetails[]) => {
this.dropdownSettings = {
singleSelection: false,
text: "Select Payer",
selectAllText: 'Select All',
unSelectAllText: 'UnSelect All',
enableSearchFilter: true,
classes: "myclass custom-class-example",
badgeShowLimit: 2,
lazyLoading: true,
labelKey: 'itemName',
primaryKey: 'id',
maxHeight: '200'
};
this.PayerDummyObjType = [];
data.forEach(x => {
this.PayerDummyObjType.push({
id:x.FILTER_VALUES, itemName:x.DISPLAY_NM
});
});
这是我的HTMl代码
<angular2-multiselect [data]="PayerDummyObjType" [(ngModel)]="PayerDummyObjTypeSelected"
[settings]="dropdownSettings" (onSelect)="onItemSelect($event)" (onDeSelect)="OnItemDeSelect($event)"
(onSelectAll)="onSelectAll($event)" (onDeSelectAll)="onDeSelectAll($event)" (onOpen)="onOpen($event)"
(onClose)="onClose($event)" (clickOutside)="onClose($event)">
</angular2-multiselect>
在下拉菜单中,我同时获得了id和itemName。请找到以下附件的屏幕截图。我没有走错地方。
答案 0 :(得分:1)
我已经通过使用模板驱动表单解决了此问题。
<angular2-multiselect [data]="PayerDummyObjType" [(ngModel)]="PayerDummyObjTypeSelected" [settings]="dropdownSettings">
<c-item>
<ng-template let-item="item">
<label style="color: #333;min-width: 150px;font-weight: 500">{{item.itemName}}</label>
</ng-template>
</c-item>