Referencing the hierachy via JavaScript

Example

We have a hierachy object called "aHier" with the following structure;

aHier
   product
      color
   hasLimiter

Running a hierachy

Where you have a hierachy object called "aHier";

#aHier.run();

Setting the value of a node of the hierachy

Set the value of the first root node [i.e. "product"] on the hierachy to "THX-3911";

#aHier.tree[0].item.val("THX-3911");

#aHier     =   hierachy object
.tree[0]   =   reference the FIRST root node on the hierachy [product]
.item      =   get the object referenced by this node
.val("v")  =   set the object's value (the STANDARD javascript object value reference method)

Getting the value of a node of the hierachy

Get the value of the second root node [i.e. "hasLimiter"] on the hierachy;

var v = #aHier .tree[1].item.val();

#aHier     =   hierachy object
.tree[1]   =   reference the SECOND root node on the hierachy [hasLimiter]
.item      =   get the object referenced by this node
.val()     =   get the object's value (the STANDARD javascript object value reference method)

Referencing sub nodes

Set the value of the first root node's [i.e. "product"] first child [i.e. "color"] on the hierachy to "Red";

#aHier.tree[0].children[0].item.val("Red");

#aHier         =   hierachy object
.tree[0]       =   reference the FIRST root node on the hierachy [product]
.children[0]   =   reference the FIRST child node of the reference node [color]
.item          =   get the object referenced by this node
.val("Red")    =   set the object's value (the STANDARD javascript object value reference method)

Sample rollup code

var rollup = function(nodes) {
  var cst = 0; // running cost for this list of node
  for (var c=0; c < nodes.length; c++){
    // for each node in the list
    var aNode = nodes[c];
    if (aNode.selected()) {  // if the node is selected
      try {
        cst += aNode.item.prop("cost");  // add the "cost" object control property
      } catch(e) {
      }
      if ((aNode.item.aType == TYPE_LIST) || (aNode.item.aType == TYPE_BOOLEAN)) {
        try {
          cst += aNode.item.inst("cost"); // add the "cost" object instance property of the selected instance
        } catch(e) {
        }
      }
      // recurse for any children
      if (aNode.children)
        cst += rollup(aNode.children);
      // optionally set the node's "total_cost" back in an object control property
      // node.prop("total_cost",cst);
    }
  }
  return cst;
}

// call rollup
var hierachyCost = rollup(#aHier.tree);