<cfloop array="#a#" item="i">
<cfset i.setSomething('foo') />
<cfoutput>#i.getSomething()#</cfoutput>
</cfloop>
--
CFML Conventional Wisdom
http://groups.google.com/group/cfml-conventional-wisdom?hl=en?hl=en
So, Matt, if you could add my suggestion (or allow others to edit the page?), I would appreciate it.
So, Matt, if you could add my suggestion (or allow others to edit the page?), I would appreciate it.
If I didn't want email traffic I wouldn't have signed up for an email list :)
But on the topic of <cfloop> I'd also like to add my own pet peeve:
the inability to do <cfloop query="whatever" group="somecolumn"> .
There would need to be some thought on unambiguously connecting the
inner loop to the outer grouping one, but it just has always been
weird that you have to use <cfoutput> to do these sort of loops.
It's especially awkward if you're already inside a generic <cfoutput>
block and need to close that first.
Also, you might kick me for this, in cfscript I would love to see a loop construct, su) as:
loop(query=myquery){
var item = myquery.name;
}
and
loop(array=myArray, item="x"){
}
and
loop(collection=stCollection, item="x"){
}
AAAAND whilst we are at it, why isn't it:
<cfloop query="#queryname#">
instead of
<cfloop query="queryname">
On 19 Feb 2010, at 18:20, Mark Jones wrote:
> But on the topic of <cfloop> I'd also like to add my own pet peeve:
> the inability to do <cfloop query="whatever" group="somecolumn"> .
> There would need to be some thought on unambiguously connecting the
> inner loop to the outer grouping one, but it just has always been
> weird that you have to use <cfoutput> to do these sort of loops.
Mark Drew
Railo Technologies UK
Professional Open Source
skype: mark_railo
email: ma...@getrailo.com
gtalk: ma...@getrailo.com
tel: +44 7971 85 22 96
web: http://www.getrailo.com
do it with the "for(...){}" syntax and keep it like other langauges and
you have my support.
> AAAAND whilst we are at it, why isn't it:
>
> <cfloop query="#queryname#">
> instead of
> <cfloop query="queryname">
+++1 absolutely! That is a huge inconsistency and i have seen it
tripping up many a new CFML developer.
I like the idea of a generic loop instruction like those examples
because it helps tie the script language to the tag language. I think
that's CFML's biggest organizational problem: making the two coding
methods feel like one language instead of two, being able to slip
between them at will. Obviously there will be stuff that's unique one
way or another, but it would be wonderful if you could do script <->
tags translation with a handful of syntax rules. But the inevitable
script/tag beatdowns are for another thread :)
>> <cfloop query="#queryname#">
>
> +++1 absolutely! That is a huge inconsistency and i have seen it tripping
> up many a new CFML developer.
It might help in explaining to people why they don't need to do <cfset
newvar = "#oldvar#"> as well. To be honest, I've seen more people get
tripped up by the needed #s in <cfdump var="#quueryname#">. Of course,
that might not happen if the difference between strings/variable names
and the objects/variables themselves were more consistent across tags.
This is an example where the basic syntax of tags is actually the
problem, since all attributes are quoted and therefore assumed to be
strings.
<cfloop object="#ANYOBJECT#">
- ANYOBJECT can be a query, array or struct and the engine loops accordingly.
- ITEM and INDEX should both be optional, and if not specified,
variables called "item" and "index" become available automatically in
the loop.
- Most importantly, *both* ITEM and INDEX should exist for every loop
- no matter what the object is. So if you loop through an array, you
get the position in the "index" and the actual value in the "item".
With a struct, you get the key name in the "index" and the value in
the "item". With a query you get the row in the "index" and the query
row in the "item". I find it happens a lot that you code an array
loop, only to find out later that you also need the position, so you
have to refactor to a from/to loop. Why not have both?
Clarification: With a query you get the row NUMBER in the "index" and
the actual query row in the "item"