Ask a Question related to Coldfusion - Advanced Techniques, Design and Development.

  1. #1

    Default Array Reference

    This loop does not seem to like the reference to the array via
    application.production.getWorkLoad() where i is the index. Is there a way to
    reference this array without dumping it into a local variable on the page?

    Thanks for the help!

    Andy Powell

    <cfloop from="1" to="#ArrayLen(application.production.getWorkLoad() )#"
    index="i">
    <tr>
    <td><cfoutput>#application.production.getWorkLoad( )[i].id#</cfoutput></td>

    <td><cfoutput>#application.production.getWorkLoad( )[i].client.name#</cfoutput>
    </td>
    <td><cfoutput>#application.production.getWorkLoad( )[i].agent#</cfoutput></td>
    </tr>
    </cfloop>

    ajpowellatl Guest

  2. Similar Questions and Discussions

    1. Can't reference array that exists....i checked!
      Scenario: frame 1 i create array called xml_array; I then fill array with other arrays, creating a 2 dimensional array. easy enough. So i...
    2. list ($d, $row) = each ($array) by reference?
      Hi ! I always thought that while (list($d,$row) = each($array)){ $row = 5; } would operate by reference, so that $array is filled with 5...
    3. Array Reference Practice Help
      Is this a standard/normal/ok way to pass and use array by reference? @alpha=("a","b","c"); @numer=(1,2,3); #calling by reference...
    4. Array slicing through a reference: Inefficient?
      Dear Group-- I'm working on a project where I'm working with large arrays, and I'm using references to pass arrays around to reduce memory use as...
    5. Couple of array/reference type questions
      There are several array type things I find myself doing all the time and I'd like to know, once and for all, the best way to do them. For the...
  3. #2

    Default Re: Array Reference

    > application.production.getWorkLoad() where i is the index. Is there a way to
    > reference this array without dumping it into a local variable on the page?
    Not the way you're trying to do it, no.

    However you could note that a CF array is in fact an implementation of a
    Java vector, so you can do this:

    i = application.production.getWorkLoad().iterator();
    while (i.hasNext()){
    writeOutput(i.next() & "<br />");
    }

    There's a CHANCE that Macromedia (or Adobe, by the time it becomes an
    issue) might decide to stop making an Array be an implementation of a
    Vector, in which case this code might stop working. Not sure the odds of
    that happening are worth worrying about though.

    --

    Adam
    Adam Cameron Guest

  4. #3

    Default Re: Array Reference

    This works great, with one exception. When it gets to the last column of the
    last row, it bombs out. This is the error it throws:

    java.util.NoSuchElementException

    Any ideas? The data is there in the object (it's an array of objects)

    ajpowellatl Guest

  5. #4

    Default Re: Array Reference

    > This works great, with one exception. When it gets to the last column of the
    > last row, it bombs out. This is the error it throws:
    >
    > java.util.NoSuchElementException
    >
    > Any ideas? The data is there in the object (it's an array of objects)
    Can you post your code?

    --

    Adam
    Adam Cameron Guest

  6. #5

    Default Re: Array Reference

    Here you go:

    <cfscript>
    i = application.production.getWorkLoad().iterator();
    while (i.hasNext())
    {
    writeOutput("<tr>");
    writeOutput("<td>");
    writeOutput(i.next().id);
    writeOutput("</td>");
    writeOutput("<td>");
    writeOutput(i.next().client.name);
    writeOutput("</td>");
    writeOutput("<td>");
    writeOutput(i.next().agent);
    writeOutput("</td>");
    writeOutput("</tr>");
    }
    </cfscript>

    ajpowellatl Guest

  7. #6

    Default Re: Array Reference

    You don't want to make multiple calls to i.next(). Every call to i.next() takes
    you to the next item in the iterator.

    Try:

    <cfscript>
    i = application.production.getWorkLoad().iterator();
    while (i.hasNext())
    {
    tmp = i.next();
    writeOutput("<tr>");
    writeOutput("<td>");
    writeOutput(tmp.id);
    writeOutput("</td>");
    writeOutput("<td>");
    writeOutput(tmp.client.name);
    writeOutput("</td>");
    writeOutput("<td>");
    writeOutput(tmp.agent);
    writeOutput("</td>");
    writeOutput("</tr>");
    }
    </cfscript>

    Kronin555 Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139