以下是我的代码:
{this.state.tabledata.map(item,number => {
return (
{(Math.mod(number,2)==0)?( //Here parsing error
<div
style={{ padding: "2px",marginBottom:'5px',backgroundColor:'lightgray' }}
class="panel panel-default"
>
):(
<div
style={{ padding: "2px",marginBottom:'5px' }}
class="panel panel-default"
>
)}
<div
class="panel-heading"
style={{ backgroundColor: "transparent" }}
>
....
</div>
</div>
<div class="panel-body">
<div className="row">
....
</div>
</div>
);
})}
在解析错误行时,
我尝试了number%2===0
但得到了同样的错误。
谢谢。
在理解的同时让我知道是否有任何问题。
Math.mod
不是js函数,你应该使用%
。此外,您需要将map函数的参数包装到()
中。试试:
{this.state.tabledata.map((item, number) => {
return (
{number % 2 === 0 ? (
// rest of your code here