5 Replies Latest reply on Nov 26, 2008 1:53 AM by Loic.Aigon

    [JS] Is it possible to link elements of two arrays ?

    Loic.Aigon Adobe Community Professional
      Hi,
      I have a "Aa" array which is built linearly according to the page order.
      I get sth like [gs,sh,al,mo...] (they are initials).
      I use this array for creating checkboxes in a dialog, everything works fine.

      The probleme is that my dialog is not really clear.
      If I look for a special person I can't know where it appears in the dialog. I need time to find it because its name is lost in the collection of initials.
      So I think it should be better that the checkboxes list alphabetically the initials like [am, bo, dz, fm...]
      Once again I've dealt with that. I created a Bb array wich is sorted.

      My concern is that the final part of my script is an export to PDF function that pick up the checked checkboxes and define the page range from the checkedState of the checkboxes.

      As you can imagine, when I reorder the initials, it's no more linked to the corresponding real page. Doing so, it will export a page that won't be the one expected.

      So at last, my question is can I somehow link the two arrays ? Can I create the alphabetical one and then relink to the first array to get the correct index for exporting the good pages ?

      I hope I am clear enough.
      Loic
        • 1. Re: [JS] Is it possible to link elements of two arrays ?
          Loic.Aigon Adobe Community Professional
          I got a turnaround by creating 3 arrays.
          First is the basic array.
          Second is the sort array
          Third is the first array indexes position.
          So if I need a item of the second array,I refer to the index in the third array.
          I hope there is a more efficient way of doing this.
          Loic
          • 2. Re: [JS] Is it possible to link elements of two arrays ?
            [Jongware] Most Valuable Participant
            Well, how did you create the arrays?<br /><br />This<br /><pre>var sortThis = [<br />     [ "aa", 0],<br />     [ "bb", 0],<br />     [ "cc", 0],<br />     [ "dd", 0],<br />];<br /><br />for (i=0; i<sortThis.length; i++)<br />     sortThis[i][1] = i;<br /><br />alert ("name "+sortThis[1][0]+" value "+sortThis[1][1]);</pre><br />creates a 2-dimensional array. The 2nd element is set to the original order, so when you sort on the 1st element you still have a reference.
            • 3. Re: [JS] Is it possible to link elements of two arrays ?
              Loic.Aigon Adobe Community Professional
              Hi jongware,
              I like your script better than mine.
              I was building the first array Aa.
              Then copying the Aa array to a Bb with a loop .
              Then sorted the Bb array.
              Then compared Aa & Bb to get Cc that contained the index of the Aa array in the elements of Aa order.
              Finally, when needed a item in Bb, I was refering to the item in Cc (swip details).
              You can imagine all the steps I needed !
              I will keep preciously your solution.
              By the way, that's funny, because I discovered (as I havn't any development abckground) that I could use such things as aArray[x][y].
              Thanks for all.
              Loic
              • 4. Re: [JS] Is it possible to link elements of two arrays ?
                Harbs. Level 6
                Hi Loic,<br /><br />I'd probably so this by creating js objects. Something like this:<br /><br />Before reordering the array build an object like this. (I'm assuming <br />that you have two parallel arrays -- one of the initials and one which <br />contains references to pages.<br /><br />var virtualPages ={};<br />for (var i=0;i<myArray.length;i++){<br />virtualPages[myArray[i]]=pages[i];<br />}<br /><br />You can then address the pages by using myPage = vitualPages.am; or <br />myPage = vitualPages[stringOfInitials];<br /><br />HTH<br /><br />-- <br />Harbs<br />http://www.in-tools.com
                • 5. Re: [JS] Is it possible to link elements of two arrays ?
                  Loic.Aigon Adobe Community Professional
                  Hi Harbs,
                  Thanks for your advice, I can't wait trying both your method & jongware's one.
                  Just to make may speech clearer, here are two pictures.
                  The first one is a screenshot of my dialog box. It concretizes the first array Aa. It means that the initials are mounted accodringly to their page range.

                  http://www.hiboox.fr/go/images/divers/nonalpha,a842b9f3b18903a0c42708cbcc3286f2.jpg.html

                  The second screenshot consists in teh same dialog box. The checkboxes are now created regarding to the Bb array which is the Aa array sorted.
                  But the index of the checkboxes is no more coherent with the page on which appears effectively the initials.

                  http://www.hiboox.fr/go/images/divers/alpha,f5d0031f2e05cead0e5d25da95c8fc90.jpg.html

                  That's why I need to recreate the coherence between the index of the selected checkboxes and the page on which the initials really appear.
                  So my pdf export function exports the good pages.

                  Loic