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

163
Visualizações
Accessing nested endpoints inside a loop NodeJS

I am trying to add some links to a list of items. The list is made using a for loop.

for(i=0;i<links.length;i++){
<li>
<a href = "<%=links[i].path%>" > ListItem </a>
</li>
}

working fine with some of the links but others are nested links , like /path1/path2

How can I add such links using the for loop?

Edit: Links are from this array

const links = [
  {
    link: "/product1",
    title: "A",
  },
 {
    link: "/product2",
    title: "A",
  },
 {
    link: "/product3",
    title: "A",
  },
 
];

Paths are defined like this

function router (lists){
Product1Router.get('/',function(req,res){

    productdata.find() 
    .then(function (products) {

    res.render('products',{
        products,
        lists
    });

    })
})
return products1Router;
}

But the problem is unable to access list item 3, which is prod/path2, while the fr loop only adds /path2

function router (lists){
    Product2Router.get('/',function(req,res){

    productdata.find() 
    .then(function (products) {

    res.render('products',{
        products,
        lists
    });

    })
})

Product2Router.get('/path2',function(req,res){
    res.render('addNew',{
        lists
    });

});


return products1Router;
}
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