Tuesday 27 August 2013

Cfscript for loop duplicating?

Cfscript for loop duplicating?

I'm getting duplicates in an array I'm building in a for loop in
<cfscript> tags. What could be the cause of this?
I'm trying to build an array to later parse into JSON, using a query from
the database. I've checked, and the result query object doesn't contain
duplicate rows; it has two individual rows, although in the array
resulting of the for loop, I only get the first row twice.
l.response.body.result = ArrayNew(1);
for(l.i=1;l.i lte l.events.recordcount;l.i = (l.i + 1)){
ArrayAppend(l.response.body["result"], StructNew());
l.eventIndex = ArrayLen(l.response.body["result"]);
l.response.body["result"][l.eventIndex]["id"] = l.events.id;
l.response.body["result"][l.eventIndex]["start"] =
DateDiff("s","1/1/1970",l.events.startdate) * 1000;
l.response.body["result"][l.eventIndex]["end"] =
DateDiff("s","1/1/1970",l.events.enddate) * 1000;
l.response.body["result"][l.eventIndex]["title"] = l.events.title;
l.response.body["result"][l.eventIndex]["class"] = "class";
l.response.body["result"][l.eventIndex]["url"] = l.url;
}
Thanks for any help.

No comments:

Post a Comment