Javascript 在react中选择选项后,我想从下拉列表中清除字段
我想在从中选择值后清除字段,如何实现这一点。typeahead中是否有此类道具来解决此问题。我试图将输入值设置为空,但它不起作用。是否有其他方法可以实现这一点Javascript 在react中选择选项后,我想从下拉列表中清除字段,javascript,reactjs,Javascript,Reactjs,我想在从中选择值后清除字段,如何实现这一点。typeahead中是否有此类道具来解决此问题。我试图将输入值设置为空,但它不起作用。是否有其他方法可以实现这一点 const Skill = (props) => { const [singleSelections, setSingleSelections] = useState([]); const [organisation, setOrganisation] = useState([]); const [designa
const Skill = (props) => {
const [singleSelections, setSingleSelections] = useState([]);
const [organisation, setOrganisation] = useState([]);
const [designation, setDesignation] = useState([]);
const [input, setInput] = useState([]);
/* here I have handled the input changes for the dropdown*/
const handleInputChange = (e) => {
// console.log(`${typeof e}`)
if (typeof e[0] !== "undefined") {
setInput(input => [...input, {
id: e[0].id,
value: e[0].value
}]);
console.log("input values: " + JSON.stringify(e));
//give parent call back here
}
// get_choices(input);
}
const removeSkill = (value) => {
console.log("value" + value)
const newList = input.filter((item) => item.id !== value);
console.log("new" + JSON.stringify(newList))
setInput(newList);
}
/*Here I have used typeahead and I want to clear fields after selecting data from dropdown*/
<div>
<Col md={{ span: 8, offset: 2 }}
sm={12}
xs={12}>
<Form.Group controlId="jobTitle">
<Typeahead
allowNew
name="designation"
value={designation}
defaultInputValue=""
id="id"
labelKey="value"
defaultClassNames={false}
options={designation}
placeholder="Skill"
selected={designation.setSingleSelections}
onInputChange={(text, event) => {
designationName(text, "skill")
}
}
onChange={(e) => handleInputChange(e)}
/>
</Form.Group>
</Col>
</div>
const技能=(道具)=>{
常量[singleSelections,setSingleSelections]=useState([]);
const[organization,setorganization]=useState([]);
const[designation,setDesignation]=useState([]);
const[input,setInput]=useState([]);
/*在这里,我已经处理了下拉列表的输入更改*/
常量handleInputChange=(e)=>{
//console.log(`${typeof e}`)
如果(类型e[0]!=“未定义”){
设置输入(输入=>[…输入{
id:e[0]。id,
值:e[0]。值
}]);
log(“输入值:+JSON.stringify(e));
//给家长回电话
}
//获取_选项(输入);
}
const removeSkill=(值)=>{
console.log(“值”+值)
const newList=input.filter((item)=>item.id!==value);
log(“new”+JSON.stringify(newList))
设置输入(新列表);
}
/*这里我使用了typeahead,我想在从下拉列表中选择数据后清除字段*/
{
名称(文字“技能”)
}
}
onChange={(e)=>handleInputChange(e)}
/>