“antd design select filtering not worked” 可以翻译为:”antd设计选择过滤未生效”。

huangapple go评论71阅读模式
英文:

antd design select filtering not worked

问题

首先,我选择了"select"标签。在"select"标签内,我使用输入字段将"category showSearch"进行了映射,但在搜索时未找到数据。

以下是我的代码:

<Select
  bordered={false}
  placeholder="Search to Select"
  size="large"
  showSearch
  className="form-select m-3 w-96 border"
  onChange={(value) => {
    setCategory(value);
  }}
>
  {categories?.map((c) => (
    <Option key={c._id} value={c._id}>
      {c.name}
    </Option>
  ))}
</Select>
英文:

First of all i take select. Inside the select tag I have mapped category showSearch using input field but data is not found when searching.

My code is here..

&lt;Select
            bordered={false}
            placeholder=&quot;Search to Select&quot;
            size=&quot;large&quot;
            showSearch
            className=&quot;form-select m-3 w-96 border&quot;
            onChange={(value) =&gt; {
              setCategory(value);
            }}
          &gt;
            {categories?.map((c) =&gt; (
              &lt;Option key={c._id} value={c._id}&gt;
                {c.name}
              &lt;/Option&gt;
            ))}
          &lt;/Select&gt;

答案1

得分: 0

以下是翻译好的内容:

看起来你还没有添加 onSearch 属性,请尝试添加如下:

<Select
    bordered={false}
    placeholder="Search to Select"
    size="large"
    showSearch
    className="form-select m-3 w-96 border"
    onSearch={handleSearch}
    onChange={(value) => {
        setCategory(value);
    }}
>
    {categories?.map((c) => (
        <Option key={c._id} value={c._id}>
            {c.name}
        </Option>
    ))}
</Select>

以及处理搜索的函数:

async function handleSearch(userInput){
    const response = await axios.get("https://test.com",{searchValue: userInput });
    setCategories(response.data);
}
英文:

Seems like you haven't added the onSearch prop, try adding it as:

       &lt;Select
            bordered={false}
            placeholder=&quot;Search to Select&quot;
            size=&quot;large&quot;
            showSearch
            className=&quot;form-select m-3 w-96 border&quot;
            onSearch={handleSearch}
            onChange={(value) =&gt; {
              setCategory(value);
            }}
          &gt;
            {categories?.map((c) =&gt; (
              &lt;Option key={c._id} value={c._id}&gt;
                {c.name}
              &lt;/Option&gt;
            ))}
          &lt;/Select&gt;

And a function to handle search:

async function handleSearch(userInput){
     const response = await axios.get(&quot;https://test.com&quot;,{searchValue: userInput });
     setCategories(response.data);
}

huangapple
  • 本文由 发表于 2023年6月8日 11:38:22
  • 转载请务必保留本文链接:https://go.coder-hub.com/76428466.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定