How can the following be refactored so I don’t have to add a searchField each time to display the data?
/**
* selected data from grid
*/
public selectedFieldValue = '';
/**
* selected bank data from grid
*/
public selectedBankName = '';
/**
* selected city data from grid
*/
public selectedCityName = '';
/**
* selected textname data from grid
*/
public selectedTextName = '';
public onRowSelection(params: ICellRendererParams): void {
// get the selected rows from the event details
this.showContinue = true;
this.selectedFieldValue = params.data[this.searchField];
this.selectedBankName = params.data.BANKA;
this.selectedCityName = params.data.ORT01;
this.selectedTextName = params.data.RCTVCLTEXT;
}
/**
* Handler to close form and set value of selected value
* @param evt info about the selected row
* @returns void
*/
public getFieldValue(): void {
[this.isSearchFormOpen, this.showTooMuchDataAlert, this.showNoDataAlert, this.disableSave] =
[false, false, false, false];
this.myForm && this.myForm.nativeElement.updateValue(
this.fieldHash[this.searchField], this.selectedFieldValue
);
this.myForm && this.myForm.nativeElement.updateValue(
this.fieldHash[AboutMeModal.BANKA], this.selectedBankName
);
this.myForm && this.myForm.nativeElement.updateValue(
this.fieldHash[AboutMeModal.ORT01], this.selectedCityName
);
this.myForm && this.myForm.nativeElement.updateValue(
this.fieldHash[AboutMeModal.RCTVCLTEXT], this.selectedTextName
);
}
Adding them in a hash would be an approach? Just so I don’t have to initialize an empty string each time.