【发布时间】:2018-07-12 19:57:12
【问题描述】:
我在 componentDidMount() 中调用了来自服务的引导表渲染值。
我的表格示例 -
Col1 Col2 Col3
1 2 3
4 5 6
7 8 9
SumValue 15 18 //This last row holds sum of all values
如何计算 col1 中所有值的 SumValue 并显示在 Footer 中。
下面是我如何使用 react-row 将数据映射到行的代码。 而 value 是在将其设置为组件状态后,保存从服务返回的 json 文件中存在的所有列的数据的变量。
{this.state.value && this.state.value.map(function (value, ind) {
return <Row key={ind} item={value}></Row>
})
}
初始化状态
constructor(props){
super(props)
{
this.state ={
value: [], //Initializing an array
SumValue: '',
default: false,
}
}
设置状态
fetch('https://www.serviceUrl.com')
.then(res => res.json())
.then(value => {
this.setState({
value: value.empRecords, //Here its getting all records from json
default: false
});
})
如果需要更多信息,请告诉我。
【问题讨论】:
-
你不能把行保存在一个数组中吗?
-
@ChrisRosenlind - 我保存在一个数组中,我已经编辑了帖子,包括我如何初始化状态和设置状态
标签: reactjs typescript react-native react-redux