473,395 Members | 1,462 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

display content of an array

Claus Mygind
571 512MB
I have an array of objects (a hash table). My section of code, the "for in" loop (lines 18 to 41) does not execute at full speed. But if I put in an alert box (line 13) to stop program execution the the code executes when I click the Ok.

I am writing an HTML table on the fly. First I delete the content of the table, then I repopulate the table with the new content. Below the following code I display how I create the arrays (which naturally comes before this code in the actual program):

I have experimented with both using the day of the week number and the actual name of the day of the week neither way seems to work.

Attached is also a visual of the array structure.

Expand|Select|Wrap|Line Numbers
  1. function drawRTable(tbody) {
  2.     var tr, td;
  3.     tbody = document.getElementById(tbody);
  4.  
  5.     // remove existing rows, if any
  6.     while (tbody.rows.length > 0) {
  7.         tbody.deleteRow(0);
  8.     }
  9.  
  10.     var cHeaderFlag = true
  11.  
  12. //when this line is inserted the following for in loop executes
  13. alert("stop1");
  14.  
  15. /*
  16. aWeeklyTime array of object with the days of the week each day containing a variable number of entries (not important right now as I cannot get the for in loop to execute without stopping first
  17. */
  18.     for ( var i in aWeeklyTime )
  19.     {
  20.         if (cHeaderFlag)
  21.         {
  22.                     cHeaderFlag = false
  23.             tr = tbody.insertRow(tbody.rows.length);
  24.             td = tr.insertCell(tr.cells.length);
  25.             td.setAttribute("colspan", "6");
  26.             td.setAttribute("class", "subHeading4");
  27.             var cThisWeek = aWeeklyTime[i][0].weekEnd;
  28.             td.innerHTML = 'Time entered for week ending ' + cThisWeek;
  29.         }
  30.         //display day of week name
  31.         tr = tbody.insertRow(tbody.rows.length);
  32.         td = tr.insertCell(tr.cells.length);
  33.         td.setAttribute("class", "subHeading3");
  34.         td.innerHTML = aWeeklyTime[i][0].dayName;
  35.  
  36.         //fill in content
  37. //        for ( var n in aWeeklyTime[i] )
  38. //        {
  39. //        }
  40.  
  41.     }
  42.  
  43. }
  44.  

Here is how I create the array:

The arrays in this segment are as follows

aReturn is an array created with .split to parse the ajax return string (not shown here)

aDetailTime is an array also created with .split to parse each element in the aReturn array into it's subElements (line 10 below)

aTempTime is a temporary object which has one property for each element in the aDetailTime array (lines 11 thru 27 below)

aWeeklyTime array is a public array created outside the functions. Each element of aWeeklyTime is an object representing one weekday with all its detail content. (line 44 below)

Expand|Select|Wrap|Line Numbers
  1.     }else if (aReturn[0] == "~getSummary~")
  2.     {
  3.             var wkDay = "";
  4.             for (var i = 1; i < aReturn.length; i++ )
  5.             {
  6.                 //create two arrays to store the information
  7.                 var aDetailTime = new Array();
  8.                 var aTempTime = new Array();
  9.                 //parse the string into the array using the tilde to separate each value
  10.                 aDetailTime = aReturn[i].split('~');
  11.                 aTempTime[i] = new Object();
  12.                 aTempTime[i].RECKEY         = aDetailTime[0];
  13.                 aTempTime[i].EMPNO         = aDetailTime[1];
  14.                 aTempTime[i].WORKDAY     = aDetailTime[2];
  15.                 aTempTime[i].JOBID         = aDetailTime[3];
  16.                 aTempTime[i].JDEPTID     = aDetailTime[4];
  17.                 aTempTime[i].PHASECODE     = aDetailTime[5];
  18.                 aTempTime[i].PRJCTNAME     = aDetailTime[6];
  19.                 aTempTime[i].HOURS         = aDetailTime[7];
  20.                 aTempTime[i].minutes     = aDetailTime[8].substring(1) ;
  21.                 aTempTime[i].MILES         = parseInt( aDetailTime[9], 10 );
  22.                 aTempTime[i].TOLLS         = parseFloat( aDetailTime[10] );
  23.                 aTempTime[i].STARTMILES     = parseFloat( aDetailTime[11] );
  24.                 aTempTime[i].ENDMILES     = parseFloat( aDetailTime[12] );
  25.                 aTempTime[i].APPROVED     = aDetailTime[13];
  26.                 aTempTime[i].weekEnd     = aDetailTime[14];
  27.                 aTempTime[i].isDept         = aDetailTime[15];
  28.  
  29.                 var d = new Date(aTempTime[i].WORKDAY);
  30.                 chkDay = d.getDay()
  31.  
  32.                 if (wkDay != chkDay)
  33.                 {
  34.                     wkDay = chkDay;
  35.                     var cDayName = formatDate( new Date(aTempTime[i].WORKDAY), "EE" );
  36. //                    aWeeklyTime[chkDay] = new Object();
  37.                     aWeeklyTime[cDayName] = new Object();
  38.                     var cDetailCount = 0;
  39.                 }else{
  40.                     cDetailCount +=1;
  41.                 }
  42.                 aTempTime[i].dayName     = cDayName;
  43. //                aWeeklyTime[chkDay][cDetailCount] = aTempTime[i];
  44.                 aWeeklyTime[cDayName][cDetailCount] = aTempTime[i];
  45.             }
  46.  
Attached Images
File Type: gif sample array.gif (3.2 KB, 244 views)
Jan 5 '09 #1
2 4079
Claus Mygind
571 512MB
the "for in" loop (lines 18 to 41) does not execute at full speed. But if I put in an alert box (line 13) to stop program execution the the code executes when I click the Ok.
It is all a matter of timing. 6 hours of working on this with no luck and instead it comes to me in a flash laying in bed. No matter how much you try to show the code you think is the problem, the problem always lies someplace else.

This is an ajax call to fill the hash tables (arrays). That is why it did not work at full speed, the data had not arrived.

for example (and I wish the guru's out there would have pointed this out):

In this example the browser races ahead in function A and calls C before B has returned the data (hence nothing to display, but works fine with a stop in the code like the alert box). So simply taking the call for C out of A and putting it as the last line of code in B resolves the problem

Expand|Select|Wrap|Line Numbers
  1. function A( )  //(main)
  2. {
  3.  B ( ); //(get data via Ajax
  4.  C ( ); //display data 
  5. }
  6.  
  7. function B( ) 
  8. {
  9.   Ajax call...;
  10. }
  11.  
  12. function C( )
  13. {
  14.   Display data....
  15. }
Jan 9 '09 #2
acoder
16,027 Expert Mod 8TB
Yes, this is a common problem. You could've called C() in the callback function when the readyState is 4 (complete).
Jan 9 '09 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Brian Murphy | last post by:
I have a php-based yahoo-like web directory.I wanna give webmasters the possiblity to integrate my whole directory in their websites with their own formatting.I wanna this inclusion to be possible...
5
by: christian | last post by:
Hi, i'm getting no success, with my attempt displaying some pictures one after another for i.e. some seconds. null.jpg is a white site! Really thanks for any help, regards,Christian
1
by: John Fung | last post by:
Dear Everybody, I have a double menu select javascript, could anyone know how to change it, so that the result will display in a frame name called "content", please? Here is the script....
4
by: Hardy Wang | last post by:
Hi I have a ListBox control in my ASP.NET page. After I binding data to this control, I would like to be able to change this display order of items in this control. Just like change layout...
1
by: NH | last post by:
Hi, I'm struggling to display an image on asp.net webform (vb.net). The image is stored in a image field in a sql server database. I have read a good few solutions to it and still havnt got it...
9
by: loudking | last post by:
Dear all, I am writing a client-server application and the client should upload a file to the server, then the server should display the content of the file in stdout. Because I have to deal...
15
by: cssExp | last post by:
hello, Rather than going on a wild explanation on what's the the problem, it'll be much quicker and easier if i let you look at it yourself, so I'll post my page source (actual contents taken out,...
6
sammyboy78
by: sammyboy78 | last post by:
I'm trying to display my array of objects in a GUI. How do I get JLabel to refer to the data in my objects? I've read my textbook and some tutorials online I just cannot get this. Plus all the...
3
rajiv07
by: rajiv07 | last post by:
Hi to all, I have a script to list the file names in a directory .When i run this script locally (command prompt) it displays the exact file name (even though the file name has two spaces).But i...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.