我有以下代码行。
constructor(props) {
super(props);
this.state = {
trends_1: [
{ start: [parseFloat(props.ab), parseFloat(props.cd)], end: [parseFloat(props.wy), parseFloat(props.yz)], appearance: { stroke: "green" }, type: "XLINE" }
]
};
}
我怎样才能获得parseFloat(props.ab)
和parseFloat(props.yz)
的值?
您可以使用索引位置访问它
this.state.trends_1[0].start[0]
this.state.trends_1[0].start[1]
this.state.trends_1[0].end[0]
this.state.trends_1[0].end[1]
你必须这样访问。
let ab = this.state.trends_1[0].start[0];
let cd = this.state.trends_1[0].start[1];