【问题标题】:I can't get new value from autocomplete react我无法从自动完成反应中获得新价值
【发布时间】:2021-10-07 20:08:27
【问题描述】:

我在我的 react 应用程序中使用材料 UI 的自动完成功能,我想在更改项目时获取值,但我变得未定义。

这是我的代码

<Controller
                name="partnerId"
                control={control}
                defaultValue={[]}
                render={({ field: { onChange, value } }) => (
                    <Autocomplete
                        id="filter-demo"
                        className="mt-8 mb-16"
                        defaultValue={personObj}
                        value={value}
                        onChange={(newValue) => {
                            console.log('value...', newValue)
                            onChange(newValue);
                        }}
                        variant="outlined"
                        options={partners}
                        getOptionLabel={option => option.name}
                        filterOptions={filterOptions}
                        renderInput={params => <TextField {...params} label="Partners" variant="outlined" />}
                    />
                )}
            />

【问题讨论】:

    标签: reactjs react-native autocomplete material-ui


    【解决方案1】:

    尝试 onchange 为

    
    onChange={(event,newValue) => {
                               console.log('value...', newValue)
                               onChange(newValue);
                           }}
    
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-09-13
      • 1970-01-01
      • 1970-01-01
      • 2011-09-30
      • 1970-01-01
      相关资源
      最近更新 更多