简体   繁体   English

如何在 reactjs 中使用降档设置输入值

[英]How to set input value using downshift in reactjs

I'm creating autocomplete input text box using downshiftjs.我正在使用 downshiftjs 创建自动完成输入文本框。 When the result of autocomplete is clicked, I can't set the input text.单击自动完成的结果时,我无法设置输入文本。

I'm creating the sample code codesandbox.io我正在创建示例代码codesandbox.io

The autocomplete is working:自动完成功能正在运行:

在此处输入图像描述

And it's searchable:它是可搜索的:

在此处输入图像描述

When I click the item, I can't set the input box value with the item I clicked.点击item时,无法用点击的item设置输入框值。

You mast define itemToString function in hook, because you use array of object as select items.您可以在挂钩中定义itemToString function,因为您使用 object 数组作为 select 项目。 And some fix in <li> markup.并在<li>标记中进行了一些修复。

Edited working example:https://codesandbox.io/s/reverent-kepler-4v42x?file=/src/App.js编辑工作示例:https://codesandbox.io/s/reverent-kepler-4v42x?file=/src/App.js

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM