admin管理员组文章数量:1345452
I wonder what is the best way to pass an array to IJSRuntime.InvokeAsync
.
The problem I stumbled upon is that blazor will pass each element of the array as a parameter to the javascript function since InvokeAsync has an open parameter list and will not know if you just passed arguments of the same type or an array.
For now I just go with a second parameter like InvokeAsync("functionname", array, false)
.
Any other suggestions? Better solutions?
I wonder what is the best way to pass an array to IJSRuntime.InvokeAsync
.
The problem I stumbled upon is that blazor will pass each element of the array as a parameter to the javascript function since InvokeAsync has an open parameter list and will not know if you just passed arguments of the same type or an array.
For now I just go with a second parameter like InvokeAsync("functionname", array, false)
.
Any other suggestions? Better solutions?
Share Improve this question edited Aug 4, 2021 at 16:15 Tomerikoo 19.5k16 gold badges55 silver badges67 bronze badges asked Aug 4, 2021 at 16:09 fvetschfvetsch 1911 silver badge12 bronze badges1 Answer
Reset to default 12You'd either have to cast your array to object
* or call the Extension method directly:
var array = Array.Empty<Baz>();
// Casting to object
JS.InvokeAsync<Foo>("bar", (object)array);
// Explicitly call the extension method:
JSRuntimeExtensions.InvokeAsync<Foo>(JS, "bar", array);
Or just use the overload it thinks you are attempting to call:
JS.InvokeAsync<Foo>("bar", new object[] { array });
* Based on my limited knowledge of C#'s Overload Resolution.
本文标签: javascriptPassing Arrays to blazors IJSRuntimeInvokeAsyncStack Overflow
版权声明:本文标题:javascript - Passing Arrays to blazors IJSRuntime.InvokeAsync - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743786398a2538764.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论