【发布时间】:2018-11-13 19:00:13
【问题描述】:
在控制台中,我看到了以下数据。看来我没有正确使用地图功能:
{data: {action: [{action: "Changed", timestamp: 1499348050,…},…]}}
data:{action: [{action: "Changed", timestamp: 1499348050,…},…]}
action:[{action: "User Assist Changed", timestamp: 1499348050,…},…]
我正在尝试使用以下函数绘制数据,但屏幕为空白:
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
【问题讨论】:
-
在您的地图 console.log(data) 中,以确保您想要的数据确实存在。您提供的 JSON 的 sn-p 似乎缺少您想要在地图中访问的内容。
-
我想映射动作。
-
根据您提供的 JSON,
{data.r} cx={data.x} cy={data.y}数据没有您想要的属性。我建议您控制台data以确保您确实拥有所需的密钥。 -
{variables: {…}, refetch: ƒ, fetchMore: ƒ, updateQuery: ƒ, startPolling: ƒ, …} action: Array(1072) [0 … 99]--new line here--- 0: {action: "Changed", timestamp: 1499348050000, object: Array(1), Second: Array(1), __typename: "action", …} -
我强烈建议您只将您需要的部分数据返回给组件,而不是从您的查询返回的全部数据。这将帮助您正确定位您正在寻找的信息。 React 组件不需要其余的方法。
标签: javascript reactjs graphql react-apollo map-function