问题描述
我没有看到针对此问题的解决方案,我确信这是显而易见的。经典国家/州问题 场景: 具有两个Form.Select(语义ui-react)字段的redux表单
<FormSection name="addressInfo">
<Field
component={renderSelect}
label="Country"
fieldName="country"
name="country"
onChange={(newValue) =>
change("addressInfo.provstate",renderProvinceState(newValue))
}
options={renderCountries()}
/>
<Field
component={renderSelect}
label="Province/State"
fieldName="provstate"
name="provstate"
multiple
options={renderProvinceState("Canada")}
/>
我的选项构建器如下:
const renderCountries = () => {
if (!countries) return null;
var options = [];
Object.keys(countries).map((key) => {
options.push({
key: key,text: countries[key].country,value: countries[key].country,});
return null;
});
return options;
};
const renderProvinceState = (country) => {
if (!country) return null;
var states = countries.filter((s) => s.country == country)[0].states;
if (!states) return null;
var options = [];
Object.keys(states).map((key) => {
options.push({
key: key,text: states[key],value: states[key],});
return null;
});
return options;
};
我的下拉列表创建成功,我获得了加拿大的国家和省份列表。当我更改国家/地区时,出现以下错误:
index.js:1 Dropdown `value` must not be an array when `multiple` is not set. Either set `multiple={true}` or use a string or number value.
Warning: Failed prop type: Invalid prop `value` supplied to `Dropdown`.
我是新来的反应者,react-redux,感谢任何人可能有的见识。我曾尝试将value = {[]}添加到provstate obj,但这并不能解决任何问题。
我正在使用的实际组件如下:
export const renderSelect = ({
label,Meta,input,name,options,placeholder,}) => {
return (
<Form.Select
className={`${Meta.error && Meta.touched ? "error" : ""}`}
label={label}
name={input.name}
onChange={(e,{ value }) => input.onChange(value)}
options={options}
placeholder={placeholder}
value={input.value}
/>
);
};
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)