如何单击其他工作表中的按钮使用反应导航(React Native)

问题描述 投票:0回答:1

这是我的 profile.js 页面的一部分,其中包含输入表单。当按下提交按钮时,我想在将页面移动到另一个页面时同时按下该页面上的按钮。

Submit = () => {
let reg = /^[ A-Za-z]+$/; //hanya input karakter
const {
  NikKtp,
  Nama,
  JenisKelaminNama,
  TempatLahir,
  TanggalLahir,
  Alamat,
  NoTelephon,
  NamaPropinsi,
  NamaKabKota,
  NamaKecamatan,
  NamaKelurahan,
  MitraKelompokNama,
} = this.state;
if (
  NikKtp == "" ||
  Nama == "" ||
  JenisKelaminNama == "" ||
  TempatLahir == "" ||
  TanggalLahir == "" ||
  Alamat == "" ||
  NoTelephon == "" ||
  NamaPropinsi == "" ||
  NamaKabKota == "" ||
  NamaKecamatan == "" ||
  NamaKelurahan == "" ||
  MitraKelompokNama == ""
) {
  Alert.alert("Data Tidak Boleh Kosong");
} else if (reg.test(Nama) === false || reg.test(TempatLahir) === false) {
  Alert.alert("Nama & Tempat Lahir tidak boleh diisi number");
  return false;
} else {
  this.setState({ vLoader: true });
  fetch(
    "https://allapi.azurewebsites.net/0.ap1/development/petanipintar.com/Profil(D).php?RegisterId=" +
      this.state.RegisterId +
      "&UserId=" +
      this.state.UserId,
    {
      method: "post",
      headers: {
        Accept: "aplication/json",
        "Content-type": "aplication/json",
      },
      body: JSON.stringify({
        NikKtp: NikKtp,
        Nama: Nama,
        JenisKelaminNama: JenisKelaminNama,
        TempatLahir: TempatLahir,
        TanggalLahir: TanggalLahir,
        Alamat: Alamat,
        NoTelephon: NoTelephon,
        NamaPropinsi: NamaPropinsi,
        NamaKabKota: NamaKabKota,
        NamaKecamatan: NamaKecamatan,
        NamaKelurahan: NamaKelurahan,
        MitraKelompokNama: MitraKelompokNama,
      }),
    }
  )
  .then((response) => response.json())
  .then((res) => {
    Alert.alert("Success");
    this.setState({ vLoader: false });
    this.props.navigation.navigate("MenuUtama", [ this.ButtonSection() ]);
    // this.props.navigation.goBack();
  })
  .catch((error) => {
    console.error(error);
  });
}

};

这是我想要作为我的反应导航目的地的页面,其中是我想要按下的按钮脚本。

 ButtonSection = () => {
  this.getMitraId();

};

谁能帮我解决这个问题?

javascript reactjs react-native react-navigation react-native-navigation
1个回答
0
投票

useEffect
下的目标屏幕中添加您要运行的脚本 例如:

useEffect(()=>{
    // your code
},[]);
© www.soinside.com 2019 - 2024. All rights reserved.