反应本机RNPicker选择

时间:2020-08-27 10:13:26

标签: react-native

我正在使用RNPicker Select,我希望在其中从API中获取下拉项,但我正在获得没有值的空下拉列表 以下是我的代码

class Component extends Component {
  constructor(props) {
    super(props);
    this.state = {
  inqSourceList: [],
}

componentDidMount() {
    this.fetchSource();

  }
fetchSource = () => {
getInqSourceList('view=select', this, null)
}

  <RNPickerSelect
                  items={this.state.inqSourceList}
                  name="source"
                  value={this.state.source ? this.state.source.id : null}
                  onValueChange={value => {
                    this.setState({
                      source:value,
                    });
                  }}
                  style={{marginBottom: 10}}
                  
                />

我的api代码是

  export async function getModuleList  (moduleName, params,error) {
  let token = await AsyncStorage.getItem('token');
    axios
      .get(BASE_URL + moduleName + "?" + params, {

        headers: {
           Accept: 'application/json',
          'Content-Type': 'application/json',
           Authorization: "Bearer " + token },
      })
      .then((res) => {
      
          var bytes = CryptoJS.AES.decrypt(res.data.toString(), ENCDEC);
          res.data = JSON.parse(bytes.toString(CryptoJS.enc.Utf8));
          // success(res.data);
      //  console.log(res.data)
      })
      .catch(error);
  }

在这种情况下,当我使用console.log(res.data)时,我正在从后端获取值。我得到了选项列表..但下拉项为空。 谢谢

这是设置inqSourceList的函数

  export function getInqSourceList(params, _this, next) {
    getModuleList('settings/inquiry-source', params, data => {
      _this.setState({inqSourceList: data.rows});
      if (next) next(data);
    });
  }

0 个答案:

没有答案