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.










share|improve this question


























    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.










    share|improve this question
























      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.










      share|improve this question













      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






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 9 at 15:19









      Renato Veronese

      4011




      4011
























          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.






          share|improve this answer





















            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














             

            draft saved


            draft discarded


















            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

























            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.






            share|improve this answer

























              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.






              share|improve this answer























                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.






                share|improve this answer












                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.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 9 at 16:53









                Riad Baghbanli

                2,4731712




                2,4731712






























                     

                    draft saved


                    draft discarded



















































                     


                    draft saved


                    draft discarded














                    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





















































                    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







                    Popular posts from this blog

                    Schultheiß

                    Verwaltungsgliederung Dänemarks

                    Liste der Kulturdenkmale in Wilsdruff