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

151
Visualizações
How to get only the specific variation data to be display in react.js

I have created Shopping Cart the product name, image, price, and attributes are created in separate components. I'm getting an issue where I wanted to get only the specific product variation's attribute, but I got all product variation attributes as below image

enter image description here

Above show the product and its details, but the product attributes must show only its specific variation attributes but it shows all its variation attributes. below is the code and the MongoDB database structure of the product.

enter image description here

enter image description here

I don't know where I go wrong, plz help me. thank you in advance.

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

0

You can use the array filter method if you want to get a subset of the attributes. For example:

const res = {
  data: {
    VariationList: {
      Attribute: {
        Weight: 1,
        Length: 2,
        Width: 3,
        Hook: 4
      }
    }
  }
};

function getProductAttributes(data, filterList = []) {
  const entries = Object.entries(data.VariationList.Attribute);
  if (!filterList.length) return entries;
  return entries.filter((attr) => filterList.includes(attr[0]));
}

let output = getProductAttributes(res.data);
console.log(output); // [ [ 'Weight', 1 ], [ 'Length', 2 ], [ 'Width', 3 ], [ 'Hook', 4 ] ]

output = getProductAttributes(res.data, ['Weight', 'Length']);
console.log(output); // [ [ 'Weight', 1 ], [ 'Length', 2 ] ]
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