Vis.js: 加边后停留在addEdgeMode / Event

Vis.js: Stay in addEdgeMode / Event after edge adding

我想在 vis.js 添加边缘后留在 addEdgeMode。有办法实现吗?

我的想法是在添加边缘后再次启用 addEdgeMode。 添加边是否有触发事件? 我知道在操作中有 addEdge 选项。但是,这是在插入 之前 触发的。

您可以在上次添加后立即再次启用 addEdge, 像这样:

manipulation: {
          enabled: false,
          addNode: function (data, callback) {
              // filling in the popup DOM elements
              console.log('add', data);
          },
          editNode: function (data, callback) {
              // filling in the popup DOM elements
              console.log('edit', data);
          },
          addEdge: function (data, callback) {
              console.log('add edge', data);
              if (data.from == data.to) {
                  var r = confirm("Do you want to connect the node to itself?");
                  if (r === true) {
                      callback(data);
                  }
              }
              else {
                  callback(data);
              }
              // after each adding you will be back to addEdge mode
              network.addEdgeMode();
          }

请参阅此代码示例中的最后一行。

network.addEdgeMode();

这将在触发回调后立即启用 addEdge 模式。

请参阅 plunker

中的示例