【发布时间】:2020-07-09 16:01:43
【问题描述】:
我有一个 ag-grid 表,其中有一列带有值格式化程序:
{
headerName: "My column",
valueFormatter: getFormattedIndexValue,
...
}
来自getFormattedIndexValue我尝试调用异步函数:
async function getFormattedIndexValue (params) {
if (!params.value) return;
return await getDecodedValue(table, params.colDef.field, params.value);
}
这是异步函数的代码,我尝试调用:
async function getDecodedValue(table, field, value) {
const query = `function=decode&table=${table}&field=${field}&value=${value}`;
const response = await fetch('routines.php', { method: 'post', body: query, headers: {"Content-Type": "application/x-www-form-urlencoded"}});
return response.text();
}
但是这样 valueFormatter 不会返回正确的值,导致[Object Promise]。有没有办法从 valueFormatter 调用异步函数并获得正确的结果
【问题讨论】:
标签: javascript async-await ag-grid