gpt4 book ai didi

javascript - 更新数据库中的文件,React Native

转载 作者:行者123 更新时间:2023-12-02 23:25:06 25 4
gpt4 key购买 nike

我正在使用 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) 时它是空的。

我尝试打印响应,这是正确的,我认为问题在于我如何传递该值。

你能帮我吗?谢谢。

最佳答案

更新文本时需要使用状态变量,因此将 onChangeText 更改为:

onChangeText={FirstName => this.setState({ firstName:FirstName })}

之后,您还需要更改响应后定义变量的方式:

utente.Person.FirstName = this.state.firstName;

关于javascript - 更新数据库中的文件,React Native,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56775956/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com