Hi folks,
I've tried narrowing down my selector criteria, but that didn't help
much. Then I tried Brian Miller's suggestion to get my selector into a
comma delimited list like this:
myDiv = $(".CalendarWrapper"); // I'm doing this because there are three
calendars on screen
myCells = $("[EMAIL PROTECTED]" + ShiftDate + "], [EMAIL PROTECTED]" +
ShiftDate2 + "]", myDiv);
The goal of this, as I understand it, is to narrow down where in the DOM
to search and exactly what to search for. This is still pretty slow.
I'll post my code here and maybe someone can see what I'm doing wrong,
or if it's just going to be a bit slow:
------ snip ------
success: function(data){
alert("back from server");
FlexOrderData = eval("(" + data + ")");
alert("done with first evaluation");
var myRecordCount = FlexOrderData.recordcount;
var myTempDate, myBackgroundColor, myShiftDate, myCalendarCell, myCells;
var myjQueryString = "";
for(i = 0; i < myRecordCount; i++){
myShiftDate = "{ts '" +
CFJS.ListFirst(FlexOrderData.data.SHIFTDATE[i],".") + "'}";
mySelector = "[EMAIL PROTECTED]" + myShiftDate + "]";
myjQueryString = CFJS.ListAppend(myjQueryString, mySelector);
}
alert("done with first loop");
myDiv = $(".CalendarWrapper");
eval("myCells = $(\"" + myjQueryString + "\", myDiv);");
alert("done with second evaluation");
for(i = 0; i < myCells.length; i++){
myCalendarCell = $(myCells[i]);
myShiftDate = myCalendarCell.attr("dateValue");
myTempDate = $.odbcDateTimeParse(myShiftDate);
myBackgroundColor = "#ThisWeekdayColor#";
if(!(myTempDate.getDay() % 6)){
myBackgroundColor = "#ThisWeekendColor#";
}
myCalendarCell.removeClass("CalendarCellDisabled").addClass("CalendarCellEnabled").attr("state",
"Enabled").css({background:myBackgroundColor,
color:"#ThisFlexOrderEntryNormalTextColor#"});
<CFIf ParameterExists(ThisSelectedDate)>
if("#ThisSelectedDate#" == myShiftDate){
CalendarEvents(myCalendarCell.attr("id"), "click");
}
<CFElse>
CalendarEvents(myCalendarCell.attr("id"), "click");
</CFIf>
}
alert("done!");
},
------ end ------
You can see that I've put in a few alerts to roughly gage how long each
section takes. The problem crops up in the second evaluation:
eval("myCells = $(\"" + myjQueryString + "\", myDiv);");
This is taking several seconds. Everything else is lightening quick. Any
more ideas? Brandon mentioned one about using filter, but I wasn't sure
how I'd fit it into what I'm doing. Hopefully seeing all this code will
help. I just need to get it sped up. My client is very big on things
happening quickly.
Thanks,
Chris
Brandon Aaron wrote:
You should probably get an array of date values and then use a custom
filter function ... maybe something like this (untested):
var dateValues = ['date1', 'date2', 'date3'];
$("[EMAIL PROTECTED]).filter(function() {
for (var i=0; i<dateValues.length; i++);
return ($(this).attr('dateValue') == dateValues[i]);
});
--
Brandon Aaron
On 1/16/07, Christopher Jordan <[EMAIL PROTECTED]> wrote:
Hi gang,
I've got a for loop in which I have jQuery select a different DOM element
for each iteration. The code I've got that selects the element is:
FlexCell = $("[EMAIL PROTECTED]" + ShiftDate + "]");
So far, it's taking about three seconds to complete a loop of fifteen
iterations. Yikes! :o( If I remove the above line from the code, it's
lightning quick!
I should mention that the three second approximation is *after* I upgraded
to the very latest jQuery build (jquery-latest.pack.js... from the
jquery.com main page). So upgrading did give me a slight performance
increase.
Can anybody help me speed this up?
Thanks,
Chris
--
http://www.cjordan.info
_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/
_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/
--
http://www.cjordan.info
_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/