Cytoscape用React展开崩溃

问题描述

我正在使用react-cytoscapejs。我也要导入COSEBilkent布局。我希望有机会在点击时展开和折叠节点。因此,在单击名为“ parent”的节点时,我想隐藏其子级(我从最简单的示例开始,但我的目标是更复杂的东西)。我在useEffect中引用了cy核心,但是我不确定此lib是否正确,以及如何强制执行预期的行为:因此,将来我希望在示例{{ 3}}

我的代码段:

import Cytoscape from 'cytoscape';
import COSEBilkent from 'cytoscape-cose-bilkent';
import React,{ useRef,useEffect,useState } from 'react';
import CytoscapeComponent from 'react-cytoscapejs';
import expandCollapse from 'cytoscape-expand-collapse';

expandCollapse(Cytoscape);
Cytoscape.use(COSEBilkent);

const Test = ({}) => {
  const [cy,setCy] = useState(null);
  const elements = [
    { data: { id: 'parent',label: 'parent' } },{ data: { id: 'one',label: 'Node1' } },{ data: { id: 'two',label: 'Node2' } },{ data: { source: 'parent',target: 'two',label: 'Edge from parent to two' } },target: 'one',label: 'Edge from parent to one' } }
  ];

  useEffect(() => {
    if (cy) {
      cy.expandCollapse();
 
    }
  });
  const layout = { name: 'cose-bilkent' };

  return (
    <CytoscapeComponent
      cy={cy => {
        setCy(cy);
      }}
      layout={layout}
      elements={elements}
      style={{ width: '600px',height: '600px' }}
    />
  );
};

export default Test;

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)