handlebars - accessing multiple items - i must be doing it wrong

  • I'm querying a REST API from within beforeRender in several steps. Thanks bjrmatos for the help so far.

    First, I get results of patients (in an async/await) and put them here: req.data.patients

    Then, after getting the results, I get some lab results for those patients (in another async/await) and put them here: req.data.wbcs

    In my report, I use patients in a {{#each patients}}{{/each}}. Within the #each, I call a #child and pass the current patient. That call looks like this:

    {#child ../PatientHeader @data.currentPatient$={{{childTemplateSerializeData ./this}}} }

    I'm apparently not understanding how to use the wbcs either in the main template or in the child. Its structure looks like this:

    wbcs = {'12341': [{lr_csn: '12341', lr_collection_date: '2019-06-27T09:19:00.000Z', lr_rslt_value: '10.0'}], '12342': [{lr_csn: '12342', lr_collection_date: '2019-06-27T09:19:00.000Z', lr_rslt_value: '10.0'}]}

    (The 12341 number is a substitute for a patient identifier.)
    Anyway, what I thought would work in the main template (which isn't where I want to show the data, but figured I would start there) would look like this (in a div within the #each):


    Where "visits.[0].p3_csn" is part of the patient record.

    What I really want to do it to pass either the entire wbcs dataset to the child, or something like wbcs.[visits.[0].p3_csn]. What am I getting wrong here?

  • administrators

    in the main template you can do this:

    {{getValue wbcs visits.0.p3_csn}}

    you should have in helpers this function

    function getValue (wbcs, csn) {
      return wbcs[csn][0].lr_rslt_value

    What I really want to do it to pass either the entire wbcs dataset to the child

    no need for that, child templates inherit the data of parent so if wbcs is part of req.data then you can use wbcs also on the child template without passing something explicetly, passing data to child templates is just for passing some things like selections (like in your case the currentPatient), so in the case the child template has the original data and additional properties that you have defined in the child template call.

  • Awesome! That worked. I figured out how to make the calls in the #child, just how I need them.

    Tomorrow, I have two more REST API calls I need to incorporate into what you helped me with today. I think I now have the patterns so I can do them on my own. Thanks so much!

Log in to reply

Looks like your connection to jsreport forum was lost, please wait while we try to reconnect.