Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

117
Visualizações
Accessing handlebars object variable via javascript

I am using this code on the server side

app.get('/private', requiresAuth(), function (req, res) {
...
    res.render('private', {ListOfLoggedUsers: ListOfLoggedUsers});

What am I sending to the client is an array of objects which looks like this

[
  {
    userid: 'npwtest2',
    useridtimestamp: '2021-11-05T15:44:15.516Z',
    latitude: undefined,
    longitude: undefined
  },
  {
    userid: 'npwtest3',
    useridtimestamp: '2021-11-05T15:44:30.028Z',
    latitude: 15.7855745,
    longitude: 15.9264816
  },
  {
    userid: 'npwtest2@malinator.com',
    useridtimestamp: '2021-11-05T15:45:12.515Z',
    latitude: 55.7855745,
    longitude: 15.9264816
  }
]

On the client side I am using handlebars to access this variable:

<div>
        {{#each ListOfLoggedUsers}}
        <div class="row">
            <div class="col-md-12">
                <p>Logged user id: {{userid}}, Login date: {{moment useridtimestamp     format="DD.MM.YYYY HH:mm:ss"}},
                    Latitude: {{latitude}}, Longitude: {{longitude}} </p>
           </div>
        {{/each}}
</div>

This part is working fine, I am getting output which I want

I am trying to access those ListOfLoggedUsers from inline java script but without any success

<script>

var loggedUser = {{ListOfLoggedUsers}}

or 

var loggedUser = [{{ListOfLoggedUsers}}];
console.log (loggedUser)
    
</script>

Any idea how can access this array of objects inside inline javascript ? Thanks in advance.

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda