Dynamic Selection of templates

Could anyone please help me on this :
I need to dynamically select the templates which would also set the number of ports & its port ids dynamically…Cry

Just a small example :
If I need to show 3 nodes :
<span =“Apple-tab-span” style=“white-space:pre”> 1. category : CAT1
<span =“Apple-tab-span” style=“white-space:pre”> number of ports : 2
<span =“Apple-tab-span” style=“white-space:pre”> port ids : P1 , P2

2. category : CAT1
number of ports : 4
port ids : P1 , P2, P3, P4
3. category : CAT2
number of ports : 1
port id : P1
commonTemplate= go$(go.Node, "Spot", nodeStyle(),
            go$(go.Panel, "Table",
            { column: 0, alignment: go.Spot.Left }),
            go$(go.Shape, "Rectangle", { fill: mainColor, stroke: null },
            new go.Binding("figure", "figure"),
            new go.Binding("desiredSize", "size", go.Size.parse).makeTwoWay(go.Size.stringify)),
            { column: 2, alignment: go.Spot.Right })
            go$(go.Picture, { source: "", name: "pic", desiredSize: new go.Size(50, 50) },
            new go.Binding("source", "key", fnConvertKeyImage),
            new go.Binding("desiredSize", "size", go.Size.parse).makeTwoWay(go.Size.stringify)),
            makePort("1", go.Spot.Right, true, true, "black")
            <span style="line-height: 1.4;">);</span><div style="line-height: 16.7999992370605px;">

divFloor.nodeTemplateMap.add(CAT1, commonTemplate);

Have you examined the Dynamic Ports sample, http://gojs.net/latest/samples/dynamicPorts.html ? You might not need four sets of ports. If you just need some inputs and some outputs you could strip out the elements and code for the two sets that you don’t need.

Or perhaps you don’t want two columns (or two rows) of ports but want to distribute the ports anywhere around an icon. Then you could use a single collection of ports in a Spot Panel, with the itemArray bound to a single Array of objects, each describing a port, with a Binding of “alignment” to specify where each port should be. This is demonstrated by the Pipes sample: http://gojs.net/latest/samples/pipes.html.