I received the JSON response below:
{
"PatientSearchResult": {
"Patient": [{
"AccountBalanceCalcMethod": 2,
"AlternatePatientID": 0,
"AssignmentOfBenifits": 0,
"CellPhoneNumber1": null,
"CellPhoneNumber2": null,
"Citizenship": 0,
"Credential": 0,
"DateOfBirth": null,
"Deceased": 0,
"DeceasedDate": "\/Date(-62135578800000-0500)\/",
"DoesPatientHaveResidentProof": false,
"DriversLicenseNumber": null,
"DriversLicenseState": 0,
"EmailAddress1": null,
"EmailAddress2": null,
"Enabled": false,
"Ethnicity": 0,
"Firstname": "2914 FirstName"
}, {
...
},
...
]
}
}
When trying to parse this data, I came up with the following code:
function SortByName(x,y) {
return ((x.LastName == y.LastName) ?
0 : ((x.LastName > y.LastName) ? 1 : -1 ));
}
function RenderPatientSearchData(PatientSearchResponse){
var PatientSearchData = JSON.parse(PatientSearchResponse);
var results = PatientSearchData['PatientSearchResult'];
results.Patient.sort(SortByName);
for (i = 0, len = results.PatientSearchResult.Patient.length; i < len; i++) {
// some code here
}
//....
}
I would like to add a key-value pair to my JSON. Specifically, I want to append:
Header:'somevalue'
Is there a way to include a Header label in front of each item in the data, similar to categorizing items alphabetically as A Names, B Names, etc?
You can view a sample response of the data using this link:
https://github.com/appcelerator/KitchenSink/raw/master/Resources/examples/table_view_headers.js