【发布时间】:2021-11-16 09:05:21
【问题描述】:
我正在尝试将字典作为参数传递给 blazor 组件。字典需要存储
我尝试执行此操作,但收到错误消息,“'EventCallbackFactory' 没有名为 'CreateBinder' 的适用方法,但似乎具有该名称的扩展方法。扩展方法无法动态调度。”
我正在尝试做的事情是否有效,如果不是,为什么?我还有其他方法可以解决这个问题吗?
这是我的 blazor 组件的代码,供参考:
@page "/dictitemcomponent"
@using System.Collections.Generic;
<ul>
@foreach (KeyValuePair<string, dynamic> item in thisDict)
{
@if(item.Value.GetType() == typeof(Dictionary<string, dynamic>))
{
<li>@item.Key.ToString() : </li>
@foreach (var dict in item.Value)
{
<DictItemComponent thisDict=dict/>
}
}
@if(item.Value.GetType() == typeof(List<dynamic>))
{
<li>@item.Key.ToString() : </li>
@foreach (var value in item.Value)
{
<li>@value</li>
}
}
@if(item.Value.GetType() != typeof(List<dynamic>) && item.Value.GetType() != typeof(Dictionary<dynamic, dynamic>))
{
<li>@item.Key.ToString() : <input @bind="item.Value"/></li>
}
}
</ul>
@code
{
public KeyValuePair<string, dynamic> newProperty = new KeyValuePair<string, dynamic>();
[Parameter] public Dictionary<string,dynamic> thisDict {get; set;}= new Dictionary<string, dynamic>();
//convert the value of a KVP to a dictionary
public void ValueToProperty(KeyValuePair<string,dynamic> property)
{
string key = property.Key;
property = new KeyValuePair<string, dynamic>(key, new Dictionary<string, dynamic>());
}
public void ValueToList(KeyValuePair<string,dynamic> property)
{
string key = property.Key;
property = new KeyValuePair<string, dynamic>(key, new List<dynamic>());
}
}
【问题讨论】:
标签: dynamic types casting blazor