能够根据要求生成端口

时间:2019-06-21 16:55:13

标签: javascript gojs

我需要一种方法,可以根据每个节点的要求将端口添加到节点。因此,如果一个节点需要3个端口,则它只能生成3个或更多或更少。节点模板会为我的问题所在的每个节点创建相同的端口号。

我尝试创建一个用于创建端口的函数,然后在循环中调用该函数以不生成任何端口。该函数仅生成一个端口,但是如果循环第二次执行,它将不起作用。我还尝试过使用“动态端口”示例中的addPort函数,但这似乎也无法提供所需的结果。

function portGen(i){
                    ports=myDiag.model.nodeDataArray[0].ports;
                    arr=new Array();
                    return $(go.Panel, "Horizontal",
                                { column: 0, row: i+2 },
                                $(go.Shape,  // the "A" port
                                { width: 2, height: 2, portId: String(i+1), toSpot: go.Spot.Left, toLinkable:true, fromLinkable:true, toMaxLinks: 1 }),
                                $(go.TextBlock, String(i+1)) ) // "A" port label
                                }

Essentially I would lke to call the portGen function multiple times based on the no of ports to be created.

1 个答案:

答案 0 :(得分:0)

使用模板后将无法对其进行修改。相反,让您的节点数据包含您希望该节点具有的端口的描述数组,然后将Panel.itemArray绑定到该属性。

请阅读https://gojs.net/latest/intro/itemArrays.html,并查看诸如https://gojs.net/latest/samples/records.htmlhttps://gojs.net/latest/samples/dynamicPorts.html之类的示例。