Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
140 views
in Technique[技术] by (71.8m points)

javascript - 反应自动完成(React Autocomplete)

React_autosuggestion did not show suggestions while typing on input box even though the same code is copy pasted from documentation react-autosuggestion upi.

(即使从文档react-autosuggestion upi复制了相同的代码,React_autosuggestion在输入框上键入时也没有显示建议。)

<ReactAutocomplete
    items={[
    { id: 'foo', label: 'foo' },
    { id: 'bar', label: 'bar' },
    { id: 'baz', label: 'baz' },
    ]}
    shouldItemRender={(item, value) => item.label.toLowerCase().indexOf(value.toLowerCase()) > -1}
    getItemValue={item => item.label}
    renderItem={(item, highlighted) =>
    <div
        key={item.id}
        style={{ backgroundColor: highlighted ? '#eee' : 'transparent'}} >
        {item.label}
    </div>
    }
    value={value}
    onChange={e => setCurrentValue( e.target.value )}
    onSelect={value => setCurrentValue( value )}
  />

imported as:

(汇入为:)

import ReactAutocomplete from  'react-autocomplete';

and the value is declared and set using a function:

(并使用函数声明和设置该值:)

const [value,setValue]=useState('');

const setCurrentValue=(value)=>{
 console.log('hhhh',value)
 setValue(value);
}

However, as shown in the screenshot below, the suggestion is not displayed.

(但是,如下面的屏幕快照所示,该建议未显示。)

在此处输入图片说明

  ask by Goutham D translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...