我正在使用CouchDB / PouchDB更新数据库中的文档。
this.state = {
FirstName: "",
LastName: "",
DateOfBirth: "",
City: ""
};
}
//.....
global.utente.db
.localdb()
.find({
selector: params
})
.then(response => {
let utente = response.docs[0];
utente.Person.FirstName = this.state.firstName;
utente.Person.City = this.state.city;
//.....
render() {
console.log(this.state.firstName)
console.log(this.state.city)
return (
<View style={style.container}>
<View style={style.page}>
<KeyboardAwareScrollView>
<View style={style.inputContainer}>
<TextInput
style={style.inputs}
placeholder="Nome"
placeholderTextColor="#64c7c0"
keyboardType="email-address"
underlineColorAndroid="grey"
onChangeText={FirstName => this.setState({ firstName: FirstName })}
/>
</View>
<View style={style.inputContainer}>
<TextInput
style={style.inputs}
placeholder="Citta"
placeholderTextColor="#64c7c0"
keyboardType="email-address"
underlineColorAndroid="grey"
onChangeText={City => this.setState({ city: City })}
/>
</View>
<TouchableOpacity
style={[style.button, style.buttonOK]}
onPress={() => this.findUtente(this.props.cf)}
>
<Text style={style.buttonTesto}>Modifica</Text>
</TouchableOpacity>
</KeyboardAwareScrollView>
</View>
</View>
我不明白如何从表单中传递值。 因为当我打印console.log(FirstName)时它是空的。
我尝试打印响应,这是正确的,我认为问题是如何传递值。
你能帮我吗?谢谢。
答案 0 :(得分:1)
在更新文本时,您需要使用状态变量,因此将onChangeText更改为:
onChangeText={FirstName => this.setState({ firstName:FirstName })}
之后,您还需要更改响应后定义变量的方式:
utente.Person.FirstName = this.state.firstName;