wangduanduan / jsplumb-chinese-tutorial

jsplumb中文教程, README中没有的内容,可以查看项目的Wiki。有问题提issue
https://github.com/wangduanduan/jsplumb-chinese-tutorial/wiki
1.3k stars 249 forks source link

重新初始化JsPlumb 点击节点会报错 Cannot read property 'default' of undefined #27

Closed zhaosheng808 closed 4 years ago

zhaosheng808 commented 4 years ago

官网文档好像没有说如何 销毁这个实例化对象 直接将变量重置为null后重新初始化 然后点击节点 会报以下错误

jsplumb.js?6a11:6335 Uncaught TypeError: Cannot read property 'default' of undefined
    at root.jsPlumbInstance.eval (jsplumb.js?6a11:6335)

image

对应源码为mouseDownListener函数中6335行代码var def = this.sourceEndpointDefinitions[elid][type];报错 image

// when the user presses the mouse, add an Endpoint, if we are enabled.
var mouseDownListener = function (e) {
  // on right mouse button, abort.
  if (e.which === 3 || e.button === 2) {
    return;
  }

  elid = this.getId(this.getElement(elInfo.el)); // elid might have changed since this method was called to configure the element.

  // TODO store def on element.
  var def = this.sourceEndpointDefinitions[elid][type];

  // if disabled, return.
  if (!def.enabled) {
    return;
  }
  ...
}
zhaosheng808 commented 4 years ago

好吧,在vue中使用 v-for 循环时用index作为key会出现这个问题,换成唯一值就行了!

流程图更新时,会重新获取dom的id,但是vue数据更新时会复用,也会出现一些莫名问题,所以使用v-for进行数据渲染时,要给每组数据加一个key,key最好不要用index。


好像是调用reset()函数后导致的,具体什么原因不清楚