首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在select外部单击时,react- when query-builder空select

在select外部单击时,react- when query-builder空select
EN

Stack Overflow用户
提问于 2021-10-08 13:09:29
回答 1查看 158关注 0票数 0

我使用asyncFetch并从SelectWiget中选择value,在任何外部单击make empty value this select之后。

我对字段使用next配置

代码语言:javascript
复制
 products: {
      type: '!struct',
      label: 'Products',
      subfields: {
        title: {
          type: 'select',
          label: 'Name',
          fieldSettings: {
            asyncFetch: async (search, offset) => {
              const toSearch = _.isEmpty(search) ? 'null' :  search;
              const prodApi = (await axios.get(`http://localhost:8002/api/products/1/${toSearch}?offset=${offset}`, { headers: authHeader() }));
              const productsValues = prodApi.data.data.map(
                product => ({
                  title: product.title,
                  value: product.id
                })
              )

              return {
                values: productsValues,
                hasMore: true,
              }
            },
            useAsyncSearch: true,
            useLoadMore: true,
            forceAsyncSearch: false,
            allowCustomValues: false
          }
        },

另一个错误是当我选择某个值时,asyncFetch被再次调用。

这是包中的bug,还是我遗漏了一些配置?

我使用的包是react- package query-builder

EN

回答 1

Stack Overflow用户

发布于 2021-10-18 13:55:22

函数async的result中的值需要是字符串,所以函数如下:

代码语言:javascript
复制
asyncFetch: async (search, offset) => {
          const toSearch = _.isEmpty(search) ? 'null' :  search;
          const prodApi = (await axios.get(`http://localhost:8002/api/products/1/${toSearch}?offset=${offset}`, { headers: authHeader() }));
          const productsValues = prodApi.data.data.map(
            product => ({
              title: product.title,
              value: product.id.toString(),
            })
          )

          return {
            values: productsValues,
            hasMore: true,
          }
        }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69496367

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档