根据其他值更改Formik选择器选项-React Native

问题描述

我正在尝试根据用户为state选择的内容来更改country的选择器选项。现在我有两个分别对应于加拿大和美国的数组。我正在使用props.values.country.map将数组映射到选择器项,但是得到undefined is not a function。当我将props.values.country替换为CAUS时,选择器项会正确映射。如何调用国家/地区值,以便可以动态更改第二个选择器

  var CA = ['Alberta'];
  var US = [];
  return (
    <View style={styles.container}>
      <Formik
        initialValues={{
          state: '',country: '',}}
        // Form submission action
        onSubmit={async (values) => {
          addData(values);
        }}>
        {(props) => (
          <KeyboardAvoidingView
            behavior={Platform.OS === 'ios' ? 'padding' : null}
            style={{flex: 1,width: '100%'}}>
            <ScrollView style={styles.inner}>
              <Picker
                selectedValue={props.values.country}
                onValueChange={props.handleChange('country')}
                style={styles.input}>
                <Picker.Item label="Canada" value="CA" />
                <Picker.Item label="USA" value="US" />
              </Picker>
              <Picker
                selectedValue={props.values.state}
                onValueChange={props.handleChange('state')}
                style={styles.input}>
                {props.values.country.map((item,index) => {
                  return <Picker.Item label={item} value={index} key={index} />;
                })}
              </Picker>
              <View style={[{width: '90%',margin: 10,alignSelf: 'center'}]}>
                <Button
                  title="place order"
                  color="maroon"
                  onPress={props.handleSubmit}
                  style={{padding: 3,width: '80%'}}
                />
              </View>
            </ScrollView>
          </KeyboardAvoidingView>
        )}
      </Formik>

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...