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

标签 javascript react-native

我正在使用 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/

相关文章:

android - 无法更改从react-native-paper导入的按钮的背景颜色

android - react native + Android : Release build "Unfortunately App, has stopped"

javascript - 我怎样才能重新渲染 Ant 表

android - React Native - 为什么我们在 CameraRoll.getPhotos() 中使用 after 属性?

javascript - Bootstrap 固定顶部 header 的 anchor 问题

javascript - 如何从代码中动态删除div标签?

javascript - 我可以为 KendoScheduler 数据源硬编码数据吗?

javascript - Angular 解析返回函数而不是值

android - 在 Android 上更改高度时,react-native TextInput 显示错误

javascript - 如何获取新加载的图像的宽度/自然宽度?