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

132
Visualizações
How to render an array of object with specified keys

I have the below array of objects I just want to display name and its image

0: {name: 'Dips & Spreads', children_count: '4', id: 3, image: 'https://wingreens-dev.codilar.in/media/catalog/category/1_1_1.png', include_in_menu: 1, …}
1: {name: 'Hummus', children_count: '0', id: 46, image: 'https://wingreens-dev.codilar.in/media/catalog/category/1_3_1.png', include_in_menu: 1, …}
2: {name: 'Greek Yogurt', children_count: '0', id: 47, image: 'https://wingreens-dev.codilar.in/media/catalog/category/2_1_1.png', include_in_menu: 1, …}

And I tried to display the name first in the below code

renderBestSellerCategories(){
    console.log('aaa', this.bestSellerCategories);
    const listItems = this.bestSellerCategories.map((d) => <li key={d.name}>{d.name}</li>);
    if(this.bestSellerCategories.length) {
       return(
            <div>
                <h1>reactjs</h1>
            </div>
       )
    }
    else{
        return(
            <div>
                {listItems}
            </div>
        )
    }
}

render(){ return( {this.renderBestSellerCategories()}) }

I am not able to display the names in the frontend. How to do that any solution please

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

you can directly use bestSellerCategories

renderBestSellerCategories(){
    console.log('aaa', this.bestSellerCategories);
return (
            <div>
                {this.bestSellerCategories.map((d) => <li key={d.name}>{d.name}</li>);}
            </div>
)
    }
}
about 4 years ago · Juan Pablo Isaza Relatório

0

You just need to update condition as shown on link : https://stackblitz.com/edit/demo-react-class-component-pppahy?file=Demo.js

renderBestSellerCategories(){
console.log('aaa', this.bestSellerCategories);
const listItems = this.bestSellerCategories.map((d) => <li key={d.name}>{d.name}</li>);
if(!this.bestSellerCategories.length) {
   return(
        <div>
            <h1>reactjs</h1>
        </div>
   )
}
else{
    return(
        <div>
            {listItems}
        </div>
    )
}

}

about 4 years ago · Juan Pablo Isaza Relatório
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