我不确定您到底想要什么,但是您是否使用 Robot 类来模拟用户输入?
https://gojs.net/latest/extensions/Robot.html
// a shared Robot that can be used by all commands for this one Diagram
robot = new Robot(myDiagram); // defined in Robot.js
然后可以进行如下操作:
function clickLambda() {
var lambda = myDiagram.findNodeForKey("Lambda");
if (lambda === null) return;
var loc = lambda.location;
// click on Lambda
robot.mouseDown(loc.x + 10, loc.y + 10, 0, { });
robot.mouseUp(loc.x + 10, loc.y + 10, 100, { });
// Clicking is just a sequence of input events.
// There is no command in CommandHandler for such a basic gesture.
}
或:
function dragFromPalette() {
// simulate a drag-and-drop between Diagrams:
var dragdrop = { sourceDiagram: myPalette, targetDiagram: myDiagram };
robot.mouseDown(5, 5, 0, dragdrop); // this should be where the Alpha node is in the source myPalette
robot.mouseMove(60, 60, 100, dragdrop);
robot.mouseUp(100, 100, 200, dragdrop); // this is where the node will be dropped in the target myDiagram
// If successful in dragging a node from the Palette into the Diagram,
// the DraggingTool will perform a transaction.
}