如何在GoJS中获取可编辑TextBlock的文本?

时间:2016-06-09 06:42:50

标签: javascript gojs

如何在GoJS中获取可编辑TextBlock的文本?

3 个答案:

答案 0 :(得分:0)

我不确定你在问什么。您问题的字面答案是,您可以通过获取其TextBlock.text属性值从任何 TextBlock 获取文本字符串。

但是你提到TextBlock是可编辑的,所以也许你在询问如何在编辑过程中获取TextBlock.text的前一个值。

首先,验证谓词既包含原始字符串,也包含新建议的字符串:TextBlock.textValidationTextEditingTool.textValidation属性以及TextEditingTool.isValidText方法。

其次," TextEdited" DiagramEvent 获取原始字符串值 DiagramEvent.parameter DiagramEvent

答案 1 :(得分:0)

将其添加到图表的nodeTemplate中。这有帮助。

  

$(go.TextBlock,{                           可编辑:是的                       })

 myDiagram.nodeTemplate =

    $(go.Node, "Horizontal", {
            isTreeExpanded: false,
            click: showDetail
        },
        $(go.Panel, "Auto",
            $(go.Shape, "RoundedRectangle", {
                fill: "#cce6ff", // the default fill, if there is no data-binding
                stroke: "#6699ff",
                height: 40,
                strokeWidth: 2,
                portId: "",
                cursor: "pointer", // the Shape is the port, not the whole Node
            }, new go.Binding("fill", "fill")),
            $(go.TextBlock, {
                    editable: true
                },
                new go.Binding("text", "text"))
        ),
        $("TreeExpanderButton", { alignment: go.Spot.Bottom, alignmentFocus: go.Spot.Top }, { visible: true })
    );

答案 2 :(得分:0)

如果要触发在cade以下使用编辑文本块

var textBlock = myDiagram.findNodeForKey(nodekey).findObject('TextBlockName');
if (myDiagram.commandHandler.canEditTextBlock(textBlock))
    myDiagram.commandHandler.editTextBlock(textBlock);