0

I am trying to learn and develop a web app that allows the user to go through folders and view files. (Something like google drive does).

I am using Nodejs and using handlebars to render.

I referred to This link to get the json data. However I can't understand why my function rowSelected is not being triggered.

I haven't had much exposure towards Handlebars, but I can't seem to point out the problem in this.

Let me know if I need to provide any more code snippets. I don't want to include any jQuery or Ajax inside this.

Thank you

This is my content.hbs

<body>
<div style="align:center">
    <table>
        <tr>
            <th>Name</th>
            <th>Is Folder</th>
            <th>Date Modified</th>
        </tr>
        {{#each contents}}
        <tr onclick="rowSelected({{{json this}}})">
            <td>{{name}}</td>
            <td>{{isFolder}}</td>
            <td>50</td>
        </tr>
        {{/each}}
    </table>
</div>

Server.js

hbs.registerHelper('json', (context) => {
  console.log(context);
  return JSON.stringify(context).replace(/"/g, '&quot;');
});

var rowSelected = (selectedValue) => {
  console.log(`The selected value is  ${selectedValue.name}`);
}
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Sagar
  • 416
  • 7
  • 23
  • The `onclick` function runs in the browser which is a different JS environment (and usually a different computer!) to the Node.js based HTTP server you wrote. – Quentin Mar 19 '18 at 23:15
  • @Quentin Oops. Got it. Such a basic mistake. Even though both are javascript. One works as a backend and another works with front end. Guess I'll just make a get/post request on click. Thanks. – Sagar Mar 19 '18 at 23:37

0 Answers0