I have a problem to get data from returning JSON in case of nested JSON objects.
HTML code looks like:
<table>
<thead>
<tr>
<th>Name</th>
<th>DOB</th>
<th>Gender</th>
<th>Address</th>
<th>URL</th>
</tr>
</thead>
<tbody data-bind="foreach: rows">
<tr>
<td data-bind="text: resource.name[0].text"></td>
<td data-bind="text: dob"></td>
<td data-bind="text: gender"></td>
<td data-bind="text: address"></td>
<td data-bind="text: fullUrl"></td>
</tr>
</tbody>
</table>
then KnockoutJS
function PatientsViewModel() {
var self = this;
self.rows= ko.observableArray([]);
self.resources = ko.observableArray([]);
self.name = ko.observableArray([]);
self.text = ko.observable("");
self.dob = ko.observable("");
self.gender = ko.observable("");
self.address = ko.observable("");
self.fullUrl = ko.observable("");
$.getJSON(
"/proxy.php",
{
last: "john",
first: "smith",
dob: 19700101
},
function (data) {
console.log(JSON.stringify(data.entry));
self.rows(data.entry);
}
);
}
ko.applyBindings(new PatientsViewModel());
and JSON response structure looks like:
[
{
"fullUrl":"https://www.example.com/Patient/123",
"resource":{
"resourceType":"Patient",
"id":"123",
"identifier":[
{
"use":"official",
"type":{
"coding":[
{
"system":"http://hl7.org/fhir/v2/0203",
"code":"MR",
"display":"test data"
}
],
"text":"test"
},
"system":"1.2.3.4.5",
"value":"123",
"assigner":{
"display":"PatientId"
}
}
],
"active":true,
"name":[
{
"use":"usual",
"text":"John Smith",
"family":[
"Smith"
],
"given":[
"John"
]
}
],
"gender":"Male",
"birthDate":"1970-01-01",
"address":[
{
"use":"home",
"type":"both",
"line":[
""
],
"city":"",
"state":"",
"postalCode":"",
"country":""
}
]
},
"search":{
"mode":"match",
"score":0
}
}
]
and when I try to bind data from JSON response work fine only for fullUrl
can't get anything like resource.name[0].text
, resource.birthDate
etc
Any tips what I have missed?