简体   繁体   English

Graphql / React-Apollo:React Map函数错误

[英]Graphql/React-Apollo: React map function error

In the console I am seeing the following data. 在控制台中,我看到以下数据。 It appears I am not using the map function correctly: 看来我没有正确使用地图功能:

{data: {action: [{action: "Changed", timestamp: 1499348050,…},…]}}
data:{action: [{action: "Changed", timestamp: 1499348050,…},…]}
action:[{action: "User Assist Changed", timestamp: 1499348050,…},…]

I am trying to graph the data using the following function but the screen is blank: 我正在尝试使用以下功能对数据进行图形处理,但屏幕空白:

render() {
  console.log('graph nodes:', this.props.data)
  return (
    <svg width={this.props.width} height={this.props.height}>
      {Object.keys(this.props.data).map((data, index) => (
        <circle r={data.r} cx={data.x} cy={data.y} fill="red" key={index}/>
      ))}
    </svg>
  );
}//render

You need to map over action, and not the keys of data. 您需要映射操作,而不是数据键。

{
  this.props.data.action.map((data, index) => (
    <circle r={data.r} cx={data.x} cy={data.y} fill="red" key={index}/>
  );
}

This is assuming those properties do exist inside of each action. 假设这些属性确实存在于每个动作中。

If you are looking to use the map over action, try running this line in the top of your render 如果要使用“动作上方地图”,请尝试在渲染顶部运行此行

this.props.data.action.map(item => console.log("this is an action: ", item));

That will show you the information in each action, so that you can then manipulate it the way you are expecting to do so. 这将向您显示每个动作中的信息,以便您可以按预期的方式对其进行操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM