我正在使用 GOJS ( http://www.gojs.net/latest/index.html ),并且有一个图表,上面有一些节点,这些节点有自己的数据模型结构。
我正在附加一个“ObjectDoubleClicked”事件,如下所示:
Diagram.addDiagramListener("ObjectDoubleClicked", function (e)
{
// Do something
});
事件触发得很好,但我无法获取事件的主题(带节点)。 e.subject 保持未定义状态。
由于我有多个节点类型将被拖放到图表上,因此我需要管理它们。
获取双击节点的最佳方法是什么?
谢谢
最佳答案
我做了一个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 class和 go.js DiagramEvent class文档。
希望这是你想要的!
关于javascript - GoJS 图 - 获取双击的对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28016257/