简体   繁体   English

当我选择输入时,如何获取未过滤的数据列表?

[英]How to get unfiltered datalist, when i select input?

I've got input, that shows some values when i type number. 我有输入,当我输入数字时会显示一些值。 That i wanna do is show all datalist , when i try try select. 我想做的是显示所有datalist ,当我尝试尝试选择时。 I found answer , but it is written in jquery. 我找到了答案 ,但它是用jquery编写的。

How to show all option no matter what i'm input? 无论我输入什么内容,如何显示所有选项?

<span>
    <input
      type="number"
      list="values"
      value={this.state.values}
      onChange={this.valuesHandler}
    />
    <datalist id="values">
      <option value="200" />
      <option value="250" />
      <option value="300" />
      <option value="350" />
      <option value="500" />
    </datalist>
  </span>

onChange onChange

  valuesHandler(e) {
    this.setState({ values: +e.target.value })
    this.forceUpdateHandler()
  }

Now it looks like that 现在看起来像

在此处输入图片说明

But it should look like that on any value 但无论如何,它看起来应该像这样

在此处输入图片说明

Unfortunately (as of today) it is not possible to control the display of datalist options with css. 不幸的是(从今天开始)无法使用css控制datalist options的显示。

datalist was created to filter on the input as you type. datalist创建是为了在您键入时过滤输入。

I would recommend creating your own autocomplete or dropdown component using different elements if you need something more flexible. 如果需要更灵活的工具,我建议使用不同的元素创建自己的自动完成或下拉组件。

Something like react-select https://jedwatson.github.io/react-select/ might work as well. 像react-select https://jedwatson.github.io/react-select/之类的东西也可能起作用。

More info on datalist here https://www.w3schools.com/tags/tag_datalist.asp 有关数据列表的更多信息,请参见此处https://www.w3schools.com/tags/tag_datalist.asp

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

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