【问题标题】:Call React native fetch api using state value on RNPickerSelect onvaluechange使用 RNPickerSelect onvaluechange 上的状态值调用 React 本机 fetch api
【发布时间】:2021-12-28 03:48:52
【问题描述】:

我正在使用构造函数中的状态值调用 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 fetch-api


    【解决方案1】:

    这对我有用

    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)
      }
    }}
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-07-04
      • 1970-01-01
      • 2018-09-15
      • 1970-01-01
      • 2022-10-04
      • 2020-05-08
      • 1970-01-01
      • 2020-07-12
      相关资源
      最近更新 更多