[英]How to pass props value to form field in react native?
i have this form code: 我有此表单代码:
<Form>
<Item floatingLabel last>
<Label>Email</Label>
<Input onChangeText={ (text)=> this.setState({email: text}) }
/>
</Item>
<Item floatingLabel last>
<Label>Mobile</Label>
<Input onChangeText={ (text)=> this.setState({reg_mob_no: text}) }
/>
</Item>
<Item disabled floatingLabel last>
<Label>Package : {this.props.package_name}</Label>
<Input disabled onChange={(text) => this.setState({package_select:this.props.package_id}) }
/>
</Item>
<Item floatingLabel last>
<Label>Password</Label>
<Input onChangeText={ (text)=> this.setState({password: text}) }
secureTextEntry={true}/>
</Item>
<View padder>
<Button block style={{ backgroundColor:"#FF69B4" }} onPress={this.onRegisterPressed.bind(this)} >
<Text>Submit</Text>
</Button>
</View>
</Form>
i want to pass props
value to package_select
form field. 我想将
props
值传递给package_select
表单字段。 this.props.package_id
is the prop and prop value is a integer. this.props.package_id
是this.props.package_id
值是一个整数。
how will i pass prop value to form field ? 我如何将prop值传递给表单字段?
value={this.state.package_select}
When you pass package_select via props this line is wrong. 当您通过道具传递package_select时,此行是错误的。 It must be:
一定是:
value={this.props.package_select}
Also keep in mind that when you pass props from the outside to an input field you have a controlled component. 还请记住,当您将道具从外面传递到输入字段时,您将拥有一个受控组件。 You can not change the internal state of that component on value change.
您无法在值更改时更改该组件的内部状态。 So you register a callback on this component via props that is called, when the select input changes.
因此,当选择输入发生更改时,可以通过调用的props在此组件上注册一个回调。
Read and understand this: https://reactjs.org/docs/uncontrolled-components.html 阅读并了解以下内容: https : //reactjs.org/docs/un受控-components.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.