how to walk async recursively over an object, doing work (in right order) per leaf

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I'm a bit stumped on a javascript problem at the moment, I hope you
don't mind (too much) that I post it here as well, for a wider
audience..

My opensourced htmlMicroscope works well, except when you open a
sub-array that holds more than say a hundred keys. Maybe 200.

But the thing is, I'd like it to work on all kinds of arrays,
including ones that have 1500 keys in some sub-object/array somewhere.

Like for instance my serviceLog now does when viewing the hits per
month (not per day).

And I'm sure other applications that might use my htmlMicroscope will
suffer suddenly from the same problem, forcing the end-user of hm() to
mold his data at unexpected turns, and sometimes against his/her
wishes.

So I'd like to solve this issue. Please help me out here, I've been
stuck on it for the better part of a day now..

This loop needs to be a-synchronized;

function printLevel : function (data) {
  var html = '';
  if (typeof data=='object' && data!==null && data!==undefined) {
    for (var k in data) {
      // and the problem is you'd have up to several thousand var k's.
the loop needs to setTimeout after say a hundred iterations through
THIS loop...
      var v = data[k];
      html += '<tr><td>'+printVariable(k)+'</td><td>'+printVariable
(v)+'</td></tr>';
    }
  }
  return html;
}

function printVariable : function (data) {
   var t = typeof data;
   switch (t) {
     case 'number' :
     case 'string' :
     case 'boolean':
           return data;
           break;
     case 'object':
         return printLevel (data);
         break;
   }
}

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux