【发布时间】:2020-06-20 22:30:22
【问题描述】:
我在使用 promise 来等待函数结束后再返回值时遇到问题。我已经多次查看这个论坛的回复,但无法弄清楚如何让它工作。
发帖>How do I return the response from an asynchronous call?
我得到的最接近的是这个,它仍然无法正常工作。如果有人能纠正我的错误,我将不胜感激。
来自 Blazor:
string thing = await js.InvokeAsync<string>("GetThing");
到 JavaScript:
window.CreateFontThumnailArray = () =>
{
var thing = "";
let start = new Promise(function (resolve, reject) {
someObject.GetThingWithCallback(function (blob) {
thing = "some text";
//I want this to finish before parent function completes,
// and "return thing;" is called.
resolve();
});
});
Promise.all([start]);
return thing;
}
我对上述帖子中的内容有所了解,并已设法使一些测试函数工作,但在函数回调时却不行。喜欢上面的例子 "GetThingWithCallback(function(){"HERE"})"
我唯一的其他选择是让这个电话无效。然后处理回调 Blazor 端。 但如果我这样做,我将无法处理调用 JavaScript 函数后立即执行的操作。哪个是最理想的。
非常感谢任何帮助。
【问题讨论】:
标签: javascript blazor