简体   繁体   English

如何访问对象变量的字段作为道具传递给它的子组件?

[英]How can I access the object variable's fields to pass as the props to its child component?

I have a component that has another component to return. 我有一个组件,还有另一个组件要返回。

var fieldValues = {
    firstName : null,
    lastName : null,
    gender : null,
    birthtday : null,
    dialingCode: null,
    mobileNumber : null,
    request_id: null,
    textCode : null,
    email : null,
    password : null,
    tagsSelectedList : [],
}

export default class SignUp extends React.Component {

    render() {

update 更新

        return <SignUpTags
                    dialingCode = {fieldValues['dialingCode']}
                    mobileNumber = {fieldValues['mobileNumber']}
                    requestID = {fieldValues['request_id']}
                    nextStep={this.nextStep}
                    saveValues={this.saveValues}
                />
    }
}

When I load the page, I get the following errors: 加载页面时,出现以下错误:

dialingCode , mobileNumber and requestID are all undefined. dialingCodemobileNumberrequestID均未定义。

How can I access the object variable's fieds to pass as the props to its child component? 我如何访问对象变量的变量作为道具传递给它的子组件?

They should be fieldValues['dialingCode'] , fieldValues['mobileNumber'] and fieldValues['requestId'] . 它们应该是fieldValues['dialingCode']fieldValues['mobileNumber']fieldValues['requestId']

Note the ' 's indicating they are key strings and aren't variables . 注意的'表示它们是键串,不是变量。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM