I have json file with multiple results.
1 -- Sample one
jsonChanges: "{"field":"cancerType","oldValue":"Lentigo maligna melanoma","newValue":"Primary malignant melanoma of g canal"}"
In this case I am succesfully return all values from list
2 -- Sample two multiple values
jsonChanges:
"{"field":"date","oldValue":"","newValue":"Tue Mar 26 00:00:00 GMT 2019"},
{"field":"techniqueType","oldValue":"","newValue":"Intralesional"},{"field":"response","oldValue":"","newValue":"Complete Response"}"
In this case it returns empty.
In my component.ts I am using
getList(patientId?: number, pageNo?: number) {
const auditTrailSubscription =
this._auditTrailService.getAuditTrailUrl(patientId, pageNo,
GridConfig.ITEMS_PER_PAGE)
.subscribe(
result => {
try {
this.totalItems = result.recordsCount;
this.auditTrailList = result.lstRecords;
this.auditTrailList.forEach(x => x.jsonChanges =
JSON.parse(x.jsonChanges));
} catch (e) {
console.log(e);
}
},
err => {
this.handleError(err);
}
);
this.addSubscription("auditTrail", auditTrailSubscription);
}
In my html I am using
<tr *ngFor="let at of auditTrailList | paginate: { itemsPerPage:
_ITEMS_PER_PAGE, currentPage: crtPage, totalItems: totalItems }"
[attr.data-row-id]="at.userId">
<td>{{ at.userName }}</td>
<td>{{ at.timestamp | date: CUSTOM_DATE_FORMAT }}</td>
<td>{{ at.entityName }}</td>
<td>{{ at.jsonChanges.field }}</td>
<td>{{ at.jsonChanges.oldValue }}</td>
<td>{{ at.jsonChanges.newValue }}</td>
</tr>
The page looks like this
https://i.sstatic.net/w3DzH.jpg
My question is how to get multiple values and show them in new row.For returning single value it is ok. But for multiple values I have no idea.
JSON.parse(`[${x.jsonChanges}]`); however, I recommend trying to resolve this in the API if it is possible.JSON.parse([${x.jsonChanges}])didn't work and returns nothing but does not throw exception in console.