How to collapse all nodes initially but Expand only those which are satisfying a particular condition

I have a GoJS tree in which all the nodes have been added in this way:
var nodeDataArray = []; item = {} item["key"] = //someuniquevalue; item["text"] = //some text with Count; item["color"] = go.Brush.randomColor(); nodeDataArray.push(item);

Now, is there a way that during adding nodes with the above code, we could expand or collapse all of its children. My condition is that if the Count is more than 30, only then that node should be expanded, otherwise it should be collapsed.

So, in this image, all the nodes having count less than 30 should be collapsed.
Can it be done during adding a node from the above code or after creating the tree and then iterating over all the nodes?
How can I do so?

Never mind, I made it working by the following code:

myDiagram.nodes.each(function(n) { if("Count") >= 0) { if( < 30) n.collapseTree(); } })