0

I'm using handlebars with a table with many columns. The table has data from my database, arranged by ID. A button on each row (list of users), will open up a modal dialog for user information. I have my list of users populated in my template with the users in an array as a handlebars template.

I want to be able to display the correct user data on the modal based on which user's button was clicked, as each row is a different id.

I am trying code like this:

{{{allUsers.html_button_id.userName}}}

But as I've seen in other questions like this one, they suggest I use a helper function. I have tried that too, and have a return var helper like this:


getDataFromDB : function(key, index, options) {

            return key[index].value;
        }

Where in use:

{{getDataFromDB userProfile index}}

But still not coming up with anything. I cannot put in a variable into that, it says that it is invalid. I have a button that has an ID, which I want to pass to this helper function so I can use the ID as the index to iterate through my array depending on which button the user presses. Any idea how to accomplish this? I feel like I'm close

  • The first thing I don't understand is if you have all of the data you want to display for the user when its row's button is clicked or if you have to make a call to an API to fetch the data. – 76484 Jun 05 '20 at 21:07
  • Hi, thanks for the reply. The data has been populated on load, so the row's button has some data on the user. The modal is supposed to give a full picture of the user. The issue is that the modal that opens needs to display the users data, which I have waiting. But I need to display it dynamically based on the id of the row button clicked. So the modal is template-tized, waiting for the html_button_id to change the data when the button is pressed. – Mick Marsden Jun 05 '20 at 21:19
  • Do you have an `onclick` handler for the buttons? – 76484 Jun 05 '20 at 23:05
  • Yes, the onclick handler is meant to pass the id to the javascript function that is meant to return the id of the row. I just need to figure out how to output a variable into a helper function and have handlebars accept it as syntax. What function, what helper I need I'm hoping to figure out. – Mick Marsden Jun 06 '20 at 05:10
  • There may be some confusion here. Handlebars (and its helpers) have entered and exited the stage long before any user interaction (like clicks) can happen. Handlebars is for rendering only. Perhaps you should start by sharing your `onclick` handler code and we can proceed from there. – 76484 Jun 06 '20 at 14:49

0 Answers0