From 74ebfea962ce812488f89a41170b02ee112b0438 Mon Sep 17 00:00:00 2001 From: linusbrolin Date: Wed, 25 May 2016 09:38:13 +0200 Subject: [PATCH] Added selectable inputfields instead of forcing id and text. --- components/select/select.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/components/select/select.ts b/components/select/select.ts index c1f39d99..2b03fd80 100644 --- a/components/select/select.ts +++ b/components/select/select.ts @@ -116,13 +116,15 @@ let optionsTemplate = ` export class SelectComponent implements OnInit { @Input() public allowClear:boolean = false; @Input() public placeholder:string = ''; + @Input() public idField:string = 'id'; + @Input() public textField:string = 'text'; @Input() public initData:Array = []; @Input() public multiple:boolean = false; @Input() public set items(value:Array) { this._items = value; - this.itemObjects = this._items.map((item:any) => new SelectItem(item)); + this.itemObjects = this._items.map((item:any) => (typeof item === 'string' ? new SelectItem(item) : new SelectItem({id: item[this.idField], text: item[this.textField]}))); } @Input() @@ -235,7 +237,7 @@ export class SelectComponent implements OnInit { this.behavior = (this.firstItemHasChildren) ? new ChildrenBehavior(this) : new GenericBehavior(this); if (this.initData) { - this.active = this.initData.map((data:any) => new SelectItem(data)); + this.active = this.initData.map((data:any) => (typeof data === 'string' ? new SelectItem(data) : new SelectItem({id: data[this.idField], text: data[this.textField]}))); this.data.emit(this.active); } }