0
我正面臨着將所選值綁定到UI中的相應控件的問題。這是場景。我有一個下拉列表。根據下拉列表,我將把控件呈現給UI。當用戶點擊添加。我將它加到 到一個數組並顯示在UI中。如果用戶點擊刪除。我正在從數組中刪除該特定項目。但是現在,我擁有其他功能。當用戶點擊編輯按鈕時,該特定項目需要在用戶界面中呈現爲 ,即它對應的控件,即下拉列表,文本框,複選框,日期選擇器。我正在嘗試下面的代碼,並堅持如何實現這一功能。onEdit click應該將選定的值綁定到輸入控件
有人可以幫我解決這個問題嗎?
這裏是我的打字稿代碼:
export class TestClass{
Add() {
this.finalValues.push(new SelectedList(this.selectedItemType, this.txtEntered, this.date, this.chkBox));
}
HandleEdit(i) {
this.finalValues.find(i => i.attributeName);
return false;
}
HandleRemove(i) {
this.finalValues.splice(i, 1);
return false;
}
}
這裏是我的HTML代碼
<div class="col col-12 col-spacing">
<div>
<md-select [placeholder]="result" [(ngModel)]="selectedItemType" >
<md-option *ngFor='let attr of result' [value]="attr.fieldType"> {{attr.attribute}}
</md-option>
</md-select>
</div>
<div *ngIf="selectedItemType =='string' || selectedItemType =='decimal' || selectedItemType == 'text' || selectedItemType == 'integer'">
<input placeholder="Enter Text" type="text" class="input" [(ngModel)]="txtEntered">
</div>
<div>
<div *ngIf="selectedItemType == 'date'" class="col col-2 col-spacing">
<md-input-container class="datepicker-align">
<input mdInput [mdDatepicker]="startDatepicker" [(ngModel)]='date' placeholder="Select Date" name="StartDate" id="txtStrtDate"
#startDate>
<button id="btnOpnStartDate" mdSuffix [mdDatepickerToggle]="startDatepicker"></button>
</md-input-container>
<md-datepicker #startDatepicker></md-datepicker>
</div>
</div>
<div *ngIf="selectedItemType == 'boolean'">
<input type="checkbox" [(ngModel)]="chkBox" />
</div>
<button *ngIf="selectedItemType" md-raised-button (click)="Add()" color="accent">Add</button>
<md-list *ngFor='let selVal of finalValues;let i=index'>
<md-list-item>
<span> {{ selVal.attributeName }} </span>
<span *ngIf="txtEntered">{{ selVal.value }} </span>
<span *ngIf="date">{{selVal.date}} </span>
<span *ngIf="chkBox && !date && !txtEntered"> {{selVal.checked}} </span>
<a href="#" md-menu-item color="warn" (click)="HandleEdit(i)" >Edit</a>
<a href="" md-menu-item color="warn" (click)="HandleRemove(i)">Remove</a>
</md-list-item>
</md-list>
</div>
,這裏是我的模型類
export class SelectedList {
constructor(
public attributeName: any,
public value: any,
public date: any,
public checked: boolean
) {}
}