1

I am using the GOJS (http://www.gojs.net/latest/index.html) and have a diagram with some nodes on it which have their own data model structure.

I am attaching a "ObjectDoubleClicked" event like so:

    Diagram.addDiagramListener("ObjectDoubleClicked", function (e)
    {
        // Do something
    });

The event fires just fine but I am unable to get the subject (bring the node) of the event. The e.subject stays undefined.

As I have multiple node types which would be dropped on the diagram , I need to manage them.

What is the best way for me to get the node which was double clicked?

Thanks,

4

1 回答 1

4

我制作了一个JSFiddle,其中包含您所要求的基本示例。

HTML

<div id="myDiagram"></div>

CSS

#myDiagram{
    width:200px;
    height:200px;
}

您必须为图表指定宽度和高度,否则它不会显示。

JavaScript

var $ = go.GraphObject.make;
var myDiagram = $(go.Diagram, "myDiagram", {
    initialContentAlignment: go.Spot.Center,
    "undoManager.isEnabled": true
});

myDiagram.addDiagramListener("ObjectDoubleClicked", function (ev) {
    console.log(ev.subject); //Successfully logs the node you clicked.
    console.log(ev.subject.ie); //Successfully logs the node's name.
});

//(...) I've skipped the key adding, because it's not necessary to understand this code.

大部分代码取自go.js Diagram 类go.js DiagramEvent 类文档。

希望这是你想要的!

于 2015-01-19T00:20:41.757 回答