Helma logo
helma.org » Home > Stories > HopObject.list()

HopObject.list()

Returns an array including all subnodes of a HopObject.

Syntax
HopObject.list(start,count)

The start and count parameters are optional, if omitted, an array of the entire collection of subnodes is returned, otherwise only the specified range.

This function is most useful if the whole collection of a HopObject's subnodes should be retrieved as array. However, general use should be avoided in favor of the method described below.

Example
var objectList = root.list();
for (var i=0; i<objectList.length; i++){
  var myObject = objectList[i];
  res.writeln(myObject.created);
}
Wed Oct 18 02:01:41 GMT+01:00 1971
Fri Nov 03 13:25:15 GMT+01:00 2000
Mon May 29 07:43:09 GMT+01:00 1999


With increasing amounts of subnodes tied to a HopObject the use of list() becomes seriously inefficient – as long as not all subnodes really need to be read out.

This is due to the creation of a JavaScript array containing the whole bunch of subnodes each time the function is called.

Instead, it is recommended to determine the amount of subnodes using the function count() and looping through the subnode collection using the get() function.

var amount = root.size();
for (var i=0; i<amount; i++){
  var myObject = root.get(i);
  res.writeln(myObject.created);
}
Wed Oct 18 02:01:41 GMT+01:00 1971
Fri Nov 03 13:25:15 GMT+01:00 2000
Mon May 29 07:43:09 GMT+01:00 1999


... comment


Page last modified on 2006-01-09 10:46 by czv