【发布时间】:2018-04-29 03:43:06
【问题描述】:
我有一个如下的反应代码,它基本上创建了一个树形图:
class ChartModal extends Component{
constructor(props){
super(props)
}
callApi(){
fetch(someurl)
.then((result) => {
return result.json();
}).then((jsonResult) => {
console.log(jsonResult);
})
}
render(){
return(
<Modal
onOk={() => this.props.toggleVisibility()}
onCancel={() => this.props.toggleVisibility()}
visible={this.props.isVisible}
okText={'ok'}
cancelText={'cancel'}
confirmLoading={false}
title="Intent distribution chart"
>
<h1>HOWDY</h1>
<TreeMap
data = {this.callApi()}//this is where i want the data returned by apicall
width={400}
valueUnit={'count'}
/>
</Modal>
)
}
}
现在我希望 api 调用返回的数据在 tree map 组件中使用,但我现在这样做的方式似乎不起作用。
当我运行它时,tree map 中的数据为空,尽管我希望api call 返回的json 存在。
【问题讨论】:
-
你的意思是它不工作?请更具体。它会抛出错误吗?如果是这样,什么错误?给出不希望的结果?期望的结果是什么?这会返回什么?
-
@Antimony 当我运行它时,treemap 中的数据为空。
标签: javascript reactjs d3.js react-native