使用cytoscape.js,Elements数组为空

问题描述 投票:0回答:1

当我使用cytoscape.js库中的函数add(cy.add(参数))时,当我在firefox控制台上键入cy.elements时,“Elements”数组为空。

这里有一些关于我实际说的内容的图片。添加一些节点https://imgur.com/jVN079Q

试图看看在cytoscape对象中是否有与字母'e'匹配的属性,并且没有“elements”属性https://imgur.com/AgJUcjC

cy.elements未定义https://imgur.com/1le2qTx

添加新节点

let node = cy.add({
      group: 'nodes',
      data: { id: identifier,value:val},
      position: { x:200+Math.floor(Math.random() * 251), y:200+Math.floor(Math.random() * 151) }
    });

添加新边缘

      //levelPointer(), lastEdge and lastLevel return an int value
      s = 'n'+(Math.floor(lastEdge/2))+'l'+levelPointer() 
      t = 'n'+(++lastEdge)+'l'+(lastLevel+1)
      let node = cy.add({
        group: 'edges',
        data: {id:s+t,source:s,target:t}
      });
javascript cytoscape.js
1个回答
0
投票

您从控制台访问的cy不是Cytoscape实例,而是DOM元素。我的其他answer解释了如何访问与DOM元素关联的Cytoscape实例。

如果按如下方式初始化Cyroscape实例,则可以从控制台直接访问它:

var cy = window.cy = cytoscape(options);
© www.soinside.com 2019 - 2024. All rights reserved.