无法将字典作为我的DropDownList的数据源,因为字典无法IEnumerable?

问题描述

我有一本像这样的字典:

public Dictionary<string,List<Kpi>> KpiGroupDropDown { get; set; } = new Dictionary<string,List<Kpi>>();

enter image description here

现在,我想用此数据源提供我的DropDown,以便DropDown显示字典的“键”,因此我使用以下代码

<SfdropDownList TValue="string"
        TItem="Dictionary<string,List<Kpi>>"
        DataSource="@KpiGroupDropDown"
        @bind-Value="@SelectedGroupChartType"
        CssClass="custom-dropdown"
        Width="100px">
        <DropDownListEvents TValue="string" ValueChange="@OnChartTypeSelected" />
        <DropDownListFieldSettings Text="Name" />
</SfdropDownList>

但是这给了我这个错误

enter image description here

有人知道我在做什么错吗?

根据阿隆索的提示进行更新

将我的数据源更改为keyvaluePair:

//Original DataSource
public Dictionary<string,List<Kpi>>();

//Original DataSource converted to keyvaluePair
List<keyvaluePair<string,List<Kpi>>> list = new List<keyvaluePair<string,List<Kpi>>>();

看起来像这样:

enter image description here

所以它仍然是正确的,该列表包含3个项目(键->具有Kpi的列表)。

我的SF DropDownList的代码

<SfdropDownList TValue="string"
                            TItem="keyvaluePair<string,List<Kpi>>"
                            DataSource="@list"
                            @bind-Value="@SelectedGroupChartType"
                            CssClass="custom-dropdown"
                            Width="100px">
               <DropDownListEvents TValue="string" ValueChange="@OnChartTypeSelected" />
               <DropDownListFieldSettings Text="Key" />
</SfdropDownList>

我现在要做的是在“ TItem”,“ TValue”中设置正确的值。

我要实现的目标:

在下拉列表中作为可选项的键(例如“推进”),一旦选择了键和引用(例如“推进”->具有KPI的列表),就需要传递到我的onchange方法中:

private void OnChartTypeSelected(Syncfusion.Blazor.DropDowns.ChangeEventArgs<string> args)
{

}

有人知道我必须在“ TItem”,“ TValue”中加上什么以及我的onchange方法的预期类型(当前为)吗?

预先感谢

解决方法

如果只想使string的{​​{1}}键可用,请绑定到Dictionary<string,List<Kpi>>。这将返回带有所有键的KpiGroupDropDown.Keys。如果您还想引用这些值,则需要做更多的工作,或者可以通过它们的字符串索引来访问它们:

IEnumerable<string>
,

根据链接SfDropDownList

您应该设置TValue和TItem。 我以前没有使用过图书馆。 您需要测试TValue或TItem是否支持列表类型