1 Replies - 289 Views - Last Post: 07 October 2019 - 05:38 AM

#1 ben255   User is offline

  • D.I.C Addict

Reputation: 44
  • View blog
  • Posts: 528
  • Joined: 09-September 13

Issues presenting data from sqlite to handlebars

Posted 07 October 2019 - 04:37 AM

this is the page
{{#if roomData.length}}
<dl>
    {{#each roomData}}
    <dd>
        <b>{{room_id}}</b>
        <b>{{room_name}}</b>
    </dd>
    {{/each}}
</dl>
{{else}}
    <b>failed to load data</b>
{{/if}}





this is the node.js code
const roomData = {};
const roomQuery = "SELECT * FROM room"
app.get('/room.hbs', function(req, res){

  db.all(roomQuery, function(error, roomData){
    if(error){
      console.log('room data failed')
      console.log(error)
    }else{
      console.log('room data success')
      console.log(roomData)
      res.render('room.hbs', roomData)
    }
  });

});




this is the output
room data success
[ { room_id: 1, room_name: 'General\n' },
  { room_id: 2, room_name: 'Help' },
  { room_id: 3, room_name: 'School' } ]




the page loads the else statement in the handlebars "failed to load data" and i can't figure out why that is. I'm new to this development so not sure what the issue is

Is This A Good Question/Topic? 0
  • +

Replies To: Issues presenting data from sqlite to handlebars

#2 ben255   User is offline

  • D.I.C Addict

Reputation: 44
  • View blog
  • Posts: 528
  • Joined: 09-September 13

Re: Issues presenting data from sqlite to handlebars

Posted 07 October 2019 - 05:38 AM

SOLVED:

<dl>
    {{#each this}}
    <dd>
        <b>{{room_id}}</b>
        <b>{{room_name}}</b>
    </dd>
    {{/each}}
</dl>




needed to be written like this
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1