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

143
Visualizações
JavaScript: managing two separate arrays, ant design transfer component

Consider two arrays leftArray (data is local) and rightArray (data is inside server).

So my component allows users to swap elements inside the list with each other, either upload to the server or remove from server using the left and right buttons.

The left button is to remove the elements from the server and The right button is to send elements to the server.

Please refer the image below, This is what Ant design Transfer component looks like:

Ant Design Transfer Component

So my issue is when user manipulates the data, either to the left of right, I want to have all the keys which which are newly added or removed from the server. But the elements on the rightArray which is already in the server, I do not need the keys, because it is already in the server.

So how would I separate the assigned keys (right list) and unassigned keys (left list)? The function onChange runs whenever the user either clicks left or right, I initially declare two empty arrays and start concatenating, either addList or removeList, Now I want to find out exactly which keys are removed from the server and which keys are added from the server.

below is the function onChange:

if (direction === 'right') {

 addedList= addedList.concat(movedKeysRight)
 addedList= [...new Set(addedList)] // to remove duplicate elements Incase a list 
 item is added to the right, removed and then added again I don't want to repeat the keys 
 that's why I have it here
}
if (direction === 'left') {
  removedList = removedList.concat(movedKeysLeft)
  removedList= [...new Set(removedList)]
}
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