gpt4 book ai didi

javascript - DiagramListener 没有被调用?

转载 作者:行者123 更新时间:2023-11-30 19:19:12 25 4
gpt4 key购买 nike

我正在 try catch TreeExpanded 和 TreeCollapsed 事件,但没有调用相应的监听器。我已经按如下方式实现了监听器:

  myDiagram.addDiagramListener("TreeExpanded", function(e) {
console.log(">>>>> STUFF HAPPENED in TreeExpanded");

});

myDiagram.addDiagramListener("TreeCollapsed", function(e) {
console.log(">>>>> STUFF HAPPENED in TreeCollapsed");
});

myDiagram 的完整代码如下所示:

  myDiagram = $(go.Diagram, "myDiagramDiv",
{
"undoManager.isEnabled": true,
layout: $(go.TreeLayout),
"ChangedSelection": onSelectionChanged
});

function geoFunc(geoname) {
var geo = icons[geoname];
if (geo === undefined) geo = icons["heart"]; // use this for an unknown icon name
if (typeof geo === "string") {
geo = icons[geoname] = go.Geometry.parse(geo, true); // fill each geometry
}
return geo;
}

myDiagram.nodeTemplate =
$(go.Node, "Auto",
{isTreeExpanded:false},
{doubleClick: function(e, node) {node.expandTree(1);}},
$(go.Shape, "Rectangle",
{ strokeWidth: 2, stroke: colors["gray"], },
new go.Binding("fill", "color")),
$(go.TextBlock, {stroke:"black",font:"12pt sans-serif",margin:3,wrap: go.TextBlock.WrapDesiredSize},new go.Binding("text", "geo"))


);

// Define a Link template that routes orthogonally, with no arrowhead
myDiagram.linkTemplate =
$(go.Link,
{ routing: go.Link.Orthogonal, corner: 5, toShortLength: -2, fromShortLength: -2 },
$(go.Shape, { strokeWidth: 2, stroke: colors["gray"] })); // the link shape


myDiagram.addDiagramListener("TreeExpanded", function(e) {
console.log(">>>>> STUFF HAPPENED in TreeExpanded");

});

myDiagram.addDiagramListener("TreeCollapsed", function(e) {
console.log(">>>>> STUFF HAPPENED in TreeCollapsed");
});


// Create the model data that will be represented by Nodes and Links
myDiagram.model = new go.GraphLinksModel(
[

如何检测节点树何时展开或折叠,然后调用函数?

最佳答案

调用 Node.collapseTreeNode.expandTree 是一个相对低级的操作。您的 doubleClick 事件处理程序不会执行事务(但任何更改都应该),也不会引发任何事件,例如“TreeExpanded”DiagramEvent

而是调用 CommandHandler.expandTreeCommandHandler.collapseTree。例如:

  {
doubleClick: function(e, node) {
e.diagram.commandHandler.expandTree(node);
}
},

关于javascript - DiagramListener 没有被调用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57667309/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com