我试图将data.js文件中的步骤显示为节点,并试图连接这些边缘。但边缘是可见的。在那页里。我使用了反应流渲染软件包1.
当我刷新页面时,边缘是不可见的,甚至一秒钟都看不见。
我的反应元件
import React, { Component } from 'react'
import data from '../data'
import ReactFlow, {addEdge} from 'react-flow-renderer'
export class Pro2 extends Component {
constructor() {
super()
this.state = {
steps:data.map((step, index) => ({ id: step.id, data: {label: step["step-name"] }, position: {x: 500, y:100 * (index + 1)}})),
tasks:[],
sedges: data.slice(0, data.length - 1).map((step, index) => ({id:"e"+step.id+data[index+1].id, source: step.id, target: data[index+1].id, animated: true}))
}
console.log(this.state.steps, this.state.sedges)
this.handleChange = this.handleChange.bind(this)
}
handleChange(t) {
//console.log("clicked...............clicked at id", t.id, typeof t.id)
let sid = parseInt(t.id)
console.log("data length", data.length)
for(let i in data){
const step = data[i]
if(step.id == sid){
let posX
if(sid%2 == 0) posX = 200
else posX = 800
const tasknodes = step.tasks.map((task, index) => ({id: task.id, data: {label: task["name"]+"(weight: "+task.weight+")"}, position: {x:posX, y:100 * (index + sid)}}))
this.setState(prevState => ({
tasks: tasknodes
}))
}
else{
// console.log("elseeeeeeeeeeeeeee")
}
}
}
render() {
const graphStyles = { width: '100%', height: '500px' };
const elements = this.state.steps.concat(this.state.sedges).concat(this.state.tasks)
return (
<div>
{/* {BasicGraph()} */}
<ReactFlow onElementClick={this.handleChange} elements={elements} style={graphStyles} />
</div>
)
}
}
export default Pro2这是我使用过data.js的json数据
const data = [
{
"id": 1,
"step-name": "The First Step",
"tasks": [
{
"id": "11",
"name": "task-11",
"weight": 50
},
{
"id": "12",
"name": "task-12",
"weight": 60
}
]
},
{
"id": 2,
"step-name": "The Midlle Step",
"tasks": [
{
"id": "21",
"name": "task21",
"weight": 5
},
{
"id": "22",
"name": "task-22",
"weight": 60
}
]
},
{
"id": 3,
"step-name": "The Last Step",
"tasks": [
{
"id": "31",
"name": "task31",
"weight": 45
},
{
"id": "32",
"name": "task-32",
"weight": 16
}
]
}
]
export default data发布于 2020-08-03 15:50:43
正如文档中所指出的,节点和边缘的in必须是字符串。
https://stackoverflow.com/questions/62913359
复制相似问题