简体   繁体   English

ASP.NET 内核 Blazor 模板组件(带字典)

[英]ASP.NET Core Blazor templated components (WITH DICTIONARY)

I am looking to make a template component like the one over at: https://docs.microsoft.com/en-us/aspnet/core/blazor/components/templated-components?view=aspnetcore-6.0 .我正在寻找一个模板组件,例如: https://docs.microsoft.com/en-us/aspnet/core/blazor/components/templated-components?view=aspnetcore-6.0 However instead of displaying values for objects in a list I'd like to do this with a dictionary.但是,我不想在列表中显示对象的值,而是用字典来做到这一点。 If someone could link me to or show me how to do this I'd appreciate it.如果有人可以链接我或告诉我如何做到这一点,我将不胜感激。 I am using .NET Core 5我正在使用 .NET Core 5

Thanks谢谢

A Dictionary is just an IEnumerable<KeyValuePaier<T1,T2>>字典只是一个IEnumerable<KeyValuePaier<T1,T2>>

That conflicts a little with the IReadOnlyList<TItem> Items parameter but you can always use ToList()这与IReadOnlyList<TItem> Items参数有点冲突,但您始终可以使用 ToList()

<TableTemplate Items="myDictionary.ToList()" Context="kvpair" >

and maybe specify TItem="KeyValuePair<X,Y>"并且可能指定TItem="KeyValuePair<X,Y>"

In your RowTemplate yopu can then use @kvpair.Value.PhoneNumber然后在你的 RowTemplate 中你可以使用@kvpair.Value.PhoneNumber

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM