@hectorsq wrote:
I have the following model tree already loaded using a single request to the backend:
- document - group_1 - observation_1 - observation_2 - group_2 - observation_3 - observation_4
And here are the corresponding models.
app/models/document.js
export default DS.Model.extend({ code: DS.attr('string'), name: DS.attr('string'), groups: DS.hasMany('group'), });
app/models/group.js
export default DS.Model.extend({ code: DS.attr('string'), name: DS.attr('string'), document: DS.belongsTo('document'), observations: DS.hasMany('observation') });
app/models/observation.js
export default DS.Model.extend({ code: DS.attr('string'), name: DS.attr('string'), value: DS.attr('string'), group: DS.belongsTo('group') });
Having the following test data
- document code: 'progress_note' name: 'Progress note' - group code: 'patient_id' name: 'Patient data' - observation code: 'first_name' name: 'First name' value: 'David' - observation code: 'last_name' name: 'Last name' value: 'Bowie' - group code: 'vital_signs' name: 'Vital signs' - observation code: 'temperature' name: 'Temperature' value: '36.7' - observation code: 'heart_rate' name: 'Heart rate' value: '60'
I can show the data iterating over the model with the following template:
<p>{{document.name}} ({{document.code}})</p> <ul> {{#each document.groups as |group|}} <li>{{group.name}}</li> <ul> {{#each group.observations as |observation|}} <li><label>observation.name</label>{{input type="text" value=observation.value}}</li> {{/each}} </ul> {{/each}} </ul>
However I want to write a template in which the fields appear in a predefined order. As shown in the following (non working) code:
<ul> <li>{{getGroup('vital_signs').name}}<li> <ul> <li>{{input type="text" value=getObservation('vital_signs', 'heart_rate').value}}</li> <li>{{input type="text" value=getObservation('vital_signs', 'temperature').value}}</li> </ul> <li>{{getGroup('patient_id').name}}</li> <ul> <li>{{input type="text" value=getObservation('patient_id', 'first_name').value}}</li> <li>{{input type="text" value=getObservation('patient_id', 'last_name').value}}</li> </ul> </ul>
Any hints in how to implement the getGroup and getObservation functions?
Posts: 4
Participants: 2