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.