Ask a Question related to Coldfusion - Advanced Techniques, Design and Development.
-
ajpowellatl #1
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
-
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... -
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... -
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... -
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... -
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... -
Adam Cameron #2
Re: Array Reference
> application.production.getWorkLoad() where i is the index. Is there a way to
Not the way you're trying to do it, no.> reference this array without dumping it into a local variable on the page?
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
-
ajpowellatl #3
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
-
Adam Cameron #4
Re: Array Reference
> This works great, with one exception. When it gets to the last column of the
Can you post your code?> 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)
--
Adam
Adam Cameron Guest
-
ajpowellatl #5
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
-
Kronin555 #6
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



Reply With Quote

