Rearrange my array index in angular typescript
up vote
0
down vote
favorite
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.
angular typescript
add a comment |
up vote
0
down vote
favorite
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.
angular typescript
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
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.
angular typescript
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.
angular typescript
angular typescript
asked Nov 9 at 15:19
Renato Veronese
4011
4011
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
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.
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
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.
add a comment |
up vote
1
down vote
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.
add a comment |
up vote
1
down vote
up vote
1
down vote
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.
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.
answered Nov 9 at 16:53
Riad Baghbanli
2,4731712
2,4731712
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53228482%2frearrange-my-array-index-in-angular-typescript%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown