reactjs - react-awesome-query-builder 在选择外部单击时为空选择
问题描述
我使用 asyncFetch 并从 SelectWiget 中选择值,在外部单击任何值后将此选择设为空值。
我将下一个配置用于字段
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。
这是该软件包中的错误还是我缺少某些配置?
我使用的包是 react-awesome-query-builder
解决方案
函数异步结果的值需要是字符串,所以函数如下:
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,
}
}
推荐阅读
- mongodb - 手动恢复 /var/lib/mongodb 后 mongodb 未启动
- typescript - Typescript for newbies: can be typeA or typeB situation
- ios - 为什么我的 html 没有加载到我的 WKWebView
- c# - 分组类
- c++ - QT 5 - 无法连接以使用其他类中的插槽
- c# - 如何在 Selenium 上获取 SVG 的最后一个元素
- r - 如何将 sparlyr 连接到 spark 独立集群
- mysql - 公式 `mysql` 未安装
- php - 将嵌套数组中的“点表示法”键扩展到子数组
- mysql - AWS EB 操作错误“丢失与 MySQL 服务器的连接”