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

212
Visualizações
update variants in a table depending on subvariants types

I want to update the variants in a table like the figure below:

variants table

Where each variant type is mapped to another different variant type. for example, red variant type which is a variant type from color variants is mapped to L variant type which is a variant type from size variants.

The variants data structured like below:

variants sturcure

I wrote this code so far, and I am stuck at this point, any help is appreciated.

                    {data &&data.map((variant) => (
                      <>
                        {variant.variants &&
                          variant.variants.map((subVar) => (
                            <tr
                              className="whitespace-nowrap "
                              key={subVar.id}
                            >
                              <td>
                                <input
                                  checked={selectAll}
                                  type="checkbox"
                                  className="custom-control-input"
                                />
                                <label className="custom-control-label"></label>
                              </td>

                              <td className="px-6 py-4">
                                {(() => {
                                  for (let i = 0; i < variant.id; i++) {
                                    const temp = subVar.variantName;

                                    return `${temp}`;
                                  }
                                })()}
                              </td>
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Not knowing how your data is structured I might think that you could use template string, like you're doing, but adding both variants, like:

 {data &&data.map((variant) => (
              <>
                {variant.variants &&
                  variant.variants.map((subVar) => (
                    <tr
                      className="whitespace-nowrap "
                      key={subVar.id}
                    >
                      <td>
                        <input
                          checked={selectAll}
                          type="checkbox"
                          className="custom-control-input"
                        />
                        <label className="custom-control-label"></label>
                      </td>

                      <td className="px-6 py-4">
                        {(() => {
                            let tempArray = []
                            for(let x = 0; x < data.length; x++) {
                                tempArray.push(data.variants[x])
                            }
                            return tempArray.join(' / ')
                        })()}
                      </td>

When you're return a single variable you don't need to use the template string, you can simply return it.

You can read more about, here

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