【发布时间】:2019-09-23 11:37:30
【问题描述】:
我是 js 新手,很难弄清楚如何限制特定节点中的端口数量。 对于不同的节点,传入和传出端口的数量应该不同,例如start 节点应该有 0 个传入节点和 1 个传出端口,结束节点应该有 2 个传入节点和 0 个传出端口。我定义模板的代码如下:
myDiagram.nodeTemplate =
$(go.Node, "Spot",
{ locationSpot: go.Spot.Center, toolTip: tooltiptemplate },
new go.Binding("location", "loc", go.Point.parse).makeTwoWay(go.Point.stringify),
{ selectable: true, selectionAdornmentTemplate: nodeSelectionAdornmentTemplate },
{ resizable: true, resizeObjectName: "PANEL", resizeAdornmentTemplate: nodeResizeAdornmentTemplate },
{ rotatable: true, rotateAdornmentTemplate: nodeRotateAdornmentTemplate },
new go.Binding("angle").makeTwoWay(),
// the main object is a Panel that surrounds a TextBlock with a Shape
$(go.Panel, "Auto",
{ name: "PANEL" },
new go.Binding("desiredSize", "size", go.Size.parse).makeTwoWay(go.Size.stringify),
$(go.Shape, "Rectangle", // default figure
{
portId: "",
fromLinkable: true, toLinkable: true, cursor: "pointer",
fill: "white",
strokeWidth: 2,
toMaxLinks:1, //this is where i can limit the number but cant determine the type of node
fromMaxLinks:2
},
new go.Binding("figure", "figure"),
new go.Binding("fill", "fill"),
new go.Binding("stroke", "stroke")),
$(go.TextBlock,
{
font: "bold 8pt Helvetica, Arial, sans-serif",
textAlign: "center",
margin: 8,
maxSize: new go.Size(160, NaN),
wrap: go.TextBlock.WrapFit,
editable: true
},
new go.Binding("choices"),
new go.Binding("id"),
new go.Binding("State"),
new go.Binding("text").makeTwoWay())
),
// four small named ports, one on each side:
makePort("T", go.Spot.Top, false, true),
makePort("L", go.Spot.Left, true, true),
makePort("R", go.Spot.Right, true, true),
makePort("B", go.Spot.Bottom, true, false),
{ // handle mouse enter/leave events to show/hide the ports
// mouseEnter: function(e, node) { showSmallPorts(node, true); },
// mouseLeave: function(e, node) { showSmallPorts(node, false); }
}
);
正如评论中提到的,我知道我可以在哪里限制端口数量,但我无法确定当时正在处理哪个节点。
有人可以帮忙吗? 如果您需要更多说明,请发表评论。
【问题讨论】:
标签: gojs