【发布时间】:2020-07-11 20:16:09
【问题描述】:
我在 React 中使用来自https://material-table.com/ 的表格 但我正在承诺进行数据搜索。如果搜索未返回任何结果,则该表将永远加载...我的想法是显示一些消息。我怎样才能以最佳方式做到这一点?
<MaterialTable
title="Documents"
columns={cols}
data={query =>
new Promise((resolve, reject) => {
let url = global.url_base+'service'
fetch(url, {
method: 'POST',
body: JSON.stringify({
search: query.search,
pageSize: query.pageSize,
page: (query.page + 1),
id: sessionStorage.getItem('id')
}),
headers: {
"Content-type": "application/json; charset=UTF-8"
}
})
.then(response => response.json())
.then(result => {
resolve({
data: result.data,
page: result.page - 1,
totalCount: result.total,
})
})
})
}
/>
【问题讨论】: