在this.state中的访问值反应

问题描述 投票:0回答:2

我有以下代码行。

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)的值?

javascript reactjs react-native prop
2个回答
2
投票

您可以使用索引位置访问它

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]

1
投票

你必须这样访问。

let ab = this.state.trends_1[0].start[0];
let cd = this.state.trends_1[0].start[1];
© www.soinside.com 2019 - 2024. All rights reserved.