0

I have two cards in my application.

In my first card, this have index 0, my second card have index 1.

I have one variale called listAtributos that has this scructure:

0: {indexvariacaoatributo: 0, id: 5, tipovariacao: "Cor", valorvariacao: "Azul"}
1: {indexvariacaoatributo: 0, id: 7, tipovariacao: "Tamanho", valorvariacao: "P"}
2: {indexvariacaoatributo: 1, id: 6, tipovariacao: "Cor", valorvariacao: "Amarelo"}
3: {indexvariacaoatributo: 1, id: 7, tipovariacao: "Tamanho", valorvariacao: "P"}

Have one relationship in the index of my card and the index of my listAtributst (indexvariacaoatributo), through this, my elements is show in my card.

Exemple:

In card 0, that have index 0, will be show the follow items:

0: {indexvariacaoatributo: 0, id: 5, tipovariacao: "Cor", valorvariacao: "Azul"}
1: {indexvariacaoatributo: 0, id: 7, tipovariacao: "Tamanho", valorvariacao: "P"

In card 1, that have index 1, will be show the follow items:

2: {indexvariacaoatributo: 1, id: 6, tipovariacao: "Cor", valorvariacao: "Amarelo"}
3: {indexvariacaoatributo: 1, id: 7, tipovariacao: "Tamanho", valorvariacao: "P"}

At any given moment i need to remove one card. In this case, my index of listAtributos.indexvariacaoatributo will wrong.

I try to make a algoritm that have update listAtributos.indexvariacaoatributo conforms according the index.

Exemple:

If i exclude the card 0 , the indexvariacaoatributo that where 1, must be update to 0.

If i exclude the card 1, the indexvariacaoatributo that where 0, must be updated to 1.

I try something like:

 for(let i=0;i<this.listAtributos.length;i++){
  if(this.listAtributos[i].indexvariacaoatributo == index){
    this.listAtributos[i].indexvariacaoatributo = index - 1;
  }
}

But not works. And i don't think in other algoritm now.

Can somebody help me? Sorry for my english.

1 Answer 1

2

Make each card to have some kind of generated number, call it cardId. Then do not store card index in indexvariacaoatributo, but corresponding card cardId instead. Now, for each element of listAtributos you get cardId, then filter thru all cards to get one card with corresponding cardId.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.