有没有办法使用一个处理程序同时编辑图像和输入字段?

时间:2019-12-17 12:58:11

标签: javascript reactjs api react-native

我正在尝试使用react-native-image-picker编辑图像,并使用forkik输入字段。但是我有一个处理程序,当我更新图片时,文本字段仍未定义。当我同时选择它们和同时上传它们时,这给我带来了成功,但是我正在使用单独的编辑按钮,也希望它们都使用单个处理程序。

handleSubmit(values) {
      if (values){
        let obj = {};   
        obj["id"] =  this.props.reducer_data[0].user.id;
        obj["first_name"] = values.name;
        obj["last_name"] = this.props.reducer_data[0].user.last_name;   
        this.EditUserApiCall(this.state.photo , obj);
      } 
    }

和API调用

async EditUserApiCall(photo , otherParams) {
      const url = 'https://example.com/sub/cat';
      try {
          const response = await fetch(url, {
            method: 'POST', 
            body: this.createFormData(photo, otherParams),
          });
          const json = await response.json();
          this.props.userDetail(json);
      } 
      catch (error) {
          console.error('Error:', error);
          alert("Upload failed!");
      }
    }

0 个答案:

没有答案