我通过使用递增运算符在每次迭代中执行react组件中的递增操作。我无法在反应组件中执行增量运算符。请帮我解决这个问题。
import React, { Component } from 'react';
import Header from './js/components/Header';
import './App.css';
import './dist/css/bootstrap.css';
import cookie from 'react-cookie';
import Request from 'superagent';
import { browserHistory } from 'react-router';
export default class Performance extends Component {
constructor() {
super();
this.state = {
fullName : cookie.load('fullName'),
empId : cookie.load('empId'),
userResults : [{
"sectionTitle": "Customer Orientation",
"isMandatory": 0,
"question": [{
"qusId": 1,
"question": "Number of customer ",
"weightage": 15,
}]
}]
};
}
render() {
const userCount = 0;
return (
<div >
<Header />
<div className="container ">
<form className="form-signin1">
{
this.state.userResults.map(function(res)
{
var questions = res.question.map(function(res1){
return (
<tr>
<td>{res1.question}<input type="checkbox" value="" name={'ques_check_box_'+[res1.qusId]}/>
</td>
</tr>
)
});
return (
<div className="row">
{ userCount ++ } //increment by one for each iteration
<table className="table text-center" >
<thead>
<th width="400">Deliverables</th>
<th>Justifications</th>
<th>Weightage</th>
<th className="lastHead">Employee <br />Weightage</th>
</thead>
<tbody>
{questions}
</tbody>
</table>
</div>
)
})
}
</form>
</div>
</div>
);
}
}
&#13;
答案 0 :(得分:1)
您可以使用userCount
的{{1}}参数,而不是维护单独的变量(index
)。
然后.map
方法就像
render
答案 1 :(得分:0)
两个问题:
userCount
定义为常量。这意味着价值永远不会改变。那不是你想要的。userCount ++
之间的空格。