Reactjs的新功能。幫我定義data.map classname。像classname =「plan- {plan.flag}」(將被渲染爲class =「plan-red」)。如何在雙引號內包含數據值?帶數據映射的動態類名ES6
import React, { Component } from 'react';
import { Grid,Row,Col} from 'react-bootstrap';
var data = [{"aufr1":5,"dltp3":"Exclusive","cobr3":4,"lidp4":100,"stpd9":"[null]","plnm2":"plan","mpsadvid":5498,"qnty0":2350000,"lnnm3":"PR","prob5":100,"RNum":0,"llst1":"Approved","flag":"red"}];
export default class Report extends Component {
render() {
return (
<Grid id="report">
{
data.map(function(plan,i){
return (
<div className="data-wrapper plan-"+{plan.flag} key={i}>
<div className="row-wrapper plan-header">
<Row className="show-grid ">
<Col sm={3} md={3} className="plan-name">
<h6>Plan</h6>
<span>{plan.plnm2}</span>
</Col>
<Col sm={3} md={3} xsHidden>
<h6>Id</h6>
<span>{plan.plid7}</span>
</Col>
<Col sm={3} md={3} xsHidden>
<h6>Opp</h6>
<span>{plan.adas4}</span>
</Col>
<Col sm={3} md={3} xsHidden>
<h6>Mps Id</h6>
<span>{plan.llst1}</span>
</Col>
</Row>
</div>
</div>
);
})
}
</Grid>
);
}
}
https://github.com/JedWatson/classnames 使用的類名效用事情是一個非常好的方式來組成的各種事情 – thsorens
你可以把'{...}'中的任意JavaScript表達式。所以你需要的只是'{'前綴'+ someValue}'。 –
在提出新問題之前,請使用搜索。 –