我有一个来自在 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 并显示在页脚中。
下面是我如何使用 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
});
})
如果需要更多信息,请告诉我。