繁体   English   中英

如何从Gojs的滚动表中删除一行?

[英]How can I delete a row from a Scrolling Table in Gojs?

我正在Gojs中使用滚动表在两个表的行之间绘制链接(假设输入和输出表)。 输入表和输出表都是使用Gojs中的滚动表功能绘制的。

现在,我想从“输出”表中删除一行,但是从技术上讲,我没有找到任何方法来执行此操作,因为每个表都充当一个Gojs节点,并且当我单击一行时,它会选择整个表(节点)而不是该特定行。

这是我的代码:

var nodeJson;
        var $ = go.GraphObject.make;
        var inputFieldTable = [
            { ID: "001", Name: "Input 1", Text: "Err1" },
            { ID: "002", Name: "Input 2", Text: "Err2" },
            { ID: "003", Name: "Input 3", Text: "Err3" },
            { ID: "004", Name: "Input 4", Text: "Err4" },
            { ID: "005", Name: "Input 5", Text: "Err5" },
            { ID: "006", Name: "Input 6", Text: "Err6" },
            { ID: "007", Name: "Input 7", Text: "Err7" }
        ];

        var outputFieldTable = [
            { ID: "101", Name: "Output 1", Text: "Integer" },
            { ID: "102", Name: "Output 2", Text: "Integer" },
            { ID: "103", Name: "Output 3", Text: "Integer" },
            { ID: "104", Name: "Output 4", Text: "String" },
            { ID: "105", Name: "Output 5", Text: "String" },
            { ID: "106", Name: "Output 6", Text: "Double" },
            { ID: "107", Name: "Output 7", Text: "Multivalue" }
        ];
        myDiagram =
            $(go.Diagram, "myDiagramDiv",
                {
                    initialContentAlignment: go.Spot.Center,
                    "undoManager.isEnabled": true,
                    allowMove: false,
                    allowDelete: true,
                    allowCopy: false,
                    allowDragOut: false,
                    allowDrop: false
                });

        myDiagram.nodeTemplate =
            $(go.Node, "Vertical",
                {
                    selectionObjectName: "SCROLLING",
                    resizable: false, resizeObjectName: "SCROLLING",
                    portSpreading: go.Node.SpreadingNone
                },
                new go.Binding("location").makeTwoWay(),
                $(go.TextBlock,
                    { font: "bold 14px sans-serif" },
                    new go.Binding("text", "key")),
                $(go.Panel, "Auto",
                    $(go.Shape, { fill: "white" }),
                    $("ScrollingTable",
                        { stretch: go.GraphObject.Fill },
                        new go.Binding("TABLE.itemArray", "items"),
                        new go.Binding("TABLE.column", "left", function (left) { return left ? 2 : 0; }),
                        new go.Binding("desiredSize", "size").makeTwoWay(),
                        {
                            name: "SCROLLING",
                            desiredSize: new go.Size(100, 100),
                            "TABLE.itemTemplate":
                            $(go.Panel, "TableRow",
                                {
                                    defaultStretch: go.GraphObject.Horizontal,
                                    fromSpot: go.Spot.LeftRightSides,
                                    toSpot: go.Spot.LeftRightSides,
                                    fromLinkable: true,
                                    toLinkable: true,
                                    //allowDelete: true,
                                    //isGroup: true,
                                },
                                new go.Binding("portId", "Name"),
                                $(go.TextBlock, { column: 1 }, new go.Binding("text", "Name")),
                                $(go.TextBlock, { column: 2 }, new go.Binding("text", "Text"))
                            ),
                            "TABLE.defaultColumnSeparatorStroke": "gray",
                            "TABLE.defaultColumnSeparatorStrokeWidth": 0.5,
                            "TABLE.defaultRowSeparatorStroke": "gray",
                            "TABLE.defaultRowSeparatorStrokeWidth": 0.5,
                            "TABLE.defaultSeparatorPadding": new go.Margin(1, 3, 0, 3)
                        }
                    )
                )
            );

        myDiagram.model = $(go.GraphLinksModel,
            {
                linkFromPortIdProperty: "fromPort",
                linkToPortIdProperty: "toPort",
                nodeDataArray: [
                    {
                        key: "Input", left: true, location: new go.Point(0, 0), size: new go.Size(170, 100),
                        items: inputFieldTable
                    },
                    {
                        key: "Output", location: new go.Point(300, 0), size: new go.Size(170, 100),
                        items: outputFieldTable
                    }
                ]
            });

http://gojs.net/latest/samples/selectableFields.html演示了如何执行此操作。

基本上,您支持突出显示单个字段并跟踪节点中突出显示的字段,从而有效地形成所有突出显示字段的集合。 然后,您可以重写CommandHandler.deleteSelection方法以删除选定的字段(如果有),而不是删除选定的节点。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM