使用 RNPickerSelect onvaluechange 上的状态值调用 React Native fetch api

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

我正在使用构造函数中的状态值调用 fetch api (getDieselRequisitionList()),如下所示。

this.focusListener = this.props.navigation.addListener('didFocus', () => {
            this.setState({
                diesel_data: []
            })
            this.getDieselRequisitionList(this.state.selectedStatus, this.state.selectedYear, this.state.Month[this.state.selectedMonthIndex].id)
        });

我有 3 个下拉菜单。我想在 RNPickerSelect onvaluechange 上自动调用 getDieselRequisitionList,而不调用 onvaluechange 中的函数

谢谢...

reactjs react-native fetch-api
1个回答
0
投票

这对我来说是工作

onValueChange={(value, index) => {
  // console.warn(index, value)
  this.setState({
    selectedYear: value,
    selectedYearIndex: index == 0 ? null : index - 1,
  });
  if (value != selectedYear) {
    this.getDieselRequisitionListOnChange(this.state.selectedStatus, value, this.state.selectedMonth)
  }
}}
© www.soinside.com 2019 - 2024. All rights reserved.