0

Here is my Jquery Code

$(document).on("click", "a.icons", function() {
                    var eventId = $(this).data('id');
                    var patientName =  "<%= patients_list["+eventId+"].full_name%>";
                    $('#idHolder').html(patientName);

                });

What I want is to use a Javascript variable as an index of EJS Array?

Any help would be highly appreciated.

5

1 Answer 1

2

You can convert your EJS array to a JS array:

// Create a JS variable and assign your EJS variable value
var patients_list = <%- JSON.stringify(patients_list) %>;
$(document).on("click", "a.icons", function() {
  var eventId = $(this).data('id');
  var patientName =  patients_list[eventId].full_name;
  $('#idHolder').html(patientName);
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.