【问题标题】:react-admin Selectinput with default valuereact-admin 使用默认值选择输入
【发布时间】:2020-06-22 14:53:58
【问题描述】:

是否可以在选择默认值的情况下呈现 SelectInput?我需要使用选择的默认语言加载页面。谢谢。

我的代码:


export const CT_SELECT_I18N = [
    {id: 'en', text: 'English'},
    {id: 'pt', text: 'Português'},
    {id: 'es', text: 'Español'},
];

const renderSelect = ({
                          meta: {touched, error} = {},
                          input: {...inputProps},
                          ...props
                      }) => (
    <SelectInput
        error={!!(touched && error)}
        helperText={touched && error}
        {...inputProps}
        {...props}
        fullWidth
        source="idioma"
        choices={Constants.CT_SELECT_I18N}
        translateChoice={false}
        optionValue="id"
        optionText="text"
    />
);

【问题讨论】:

    标签: react-native react-admin


    【解决方案1】:

    为此使用道具initialValue

    你的 selectinput 看起来像

         <SelectInput
            error={!!(touched && error)}
            helperText={touched && error}
            {...inputProps}
            {...props}
            fullWidth
            source="idioma"
            choices={Constants.CT_SELECT_I18N}
            translateChoice={false}
            optionValue="id"
            optionText="text"
            initialValue={"en"}
        />
    

    更多:https://marmelab.com/react-admin/Inputs.html#common-input-props

    【讨论】:

      猜你喜欢
      • 2019-01-25
      • 2022-11-10
      • 1970-01-01
      • 1970-01-01
      • 2021-12-09
      • 1970-01-01
      • 1970-01-01
      • 2021-08-08
      • 1970-01-01
      相关资源
      最近更新 更多