【问题标题】:react-admin: Filter with SelectInput shows wrong valuesreact-admin:使用 SelectInput 过滤显示错误的值
【发布时间】:2021-03-31 12:21:19
【问题描述】:

我的react-admin 应用程序中的以下过滤器导致列表显示带有status === "active" 的记录和带有status === "inactive" 的记录。它应该只显示带有status === "active" 的记录。

<SelectInput 
  alwaysOn 
  source="status" 
  choices={[
    { id: "lead", name: "Lead" },
    { id: "active", name: "Aktiv" },
    { id: "inactive", name: "Inaktiv" },
  ]} 
/>

它似乎包含带有status === "inactive" 的记录,因为“inactive”包含子字符串“active”。

我能做点什么吗?我的DataProvider 配置错误吗?我正在使用react-admin-firebase

【问题讨论】:

    标签: reactjs react-admin


    【解决方案1】:

    react-admin-firebase 在搜索字符串时总是做模糊搜索:

     const isStringSearch = typeof searchValue === 'string';
      if (isStringSearch) {
        return searchThis
          .toString()
          .toLowerCase()
          .includes(searchValue.toLowerCase());
      }
    

    Source

    一种解决方案是使用数字代替status

    <SelectInput 
      alwaysOn 
      source="status" 
      choices={[
        { id: 1, name: "Lead" },
        { id: 2, name: "Aktiv" },
        { id: 3, name: "Inaktiv" },
      ]} 
    />
    

    另一个解决方案是启用延迟加载以直接针对您的 Firebase 进行搜索。

    【讨论】:

      猜你喜欢
      • 2021-11-03
      • 2019-02-15
      • 2019-08-04
      • 1970-01-01
      • 1970-01-01
      • 2019-12-02
      • 1970-01-01
      • 2020-05-04
      • 2013-12-11
      相关资源
      最近更新 更多