单击提交按钮后,查询将转到Neo4j DB,并将响应发送回去。另外,单击按钮时,另一个函数会将数据发送到Graph函数@Override
public void onDataChanged() {
if (progressBar != null) {
progressBar.setVisibility(View.GONE);
}
}
。一旦在Graph函数中,我尝试渲染图,但是React表示map未定义。但是,来自Graph内部的道具控制台日志显示:{this.state.submit && this.displayElements()}
。我在地图之前尝试了不同的组合,但似乎没有任何效果(this.props.nodes,this.state.action等)。
显示功能(通过道具作为节点发送数据)
{data:{action: "Changed", timestamp: 1499348050, object: Array(1), Second: Array(1), __typename: "action", …}
图形功能
displayElements = () => {
const {data:{loading, error, action}} = this.props;
console.log(this.props);
if(loading) {
return <option disabled>Loading...</option>;
}else if (error){
return<p>Error!</p>;
}
return (
<Graph nodes={this.data}/> <--Sending data to Graph via props as nodes
);
}
答案 0 :(得分:1)
map用于数组,但是您传递的对象{data:{action: "Changed", timestamp: 1499348050, object: Array(1), Second: Array(1), __typename: "action", …}
解决方案可以是Object.keys(this.state.nodes.action).map(()=>{...}
{Object.keys(this.state.nodes.action).map((node, index) =>(
<circle r={node.r} cx={node.x} cy={node.y} fill="red" key={index}/>
))}