来自外部API的动态数据的Radzen Blazor下拉列表
我正在从外部API中获取数据,并且代码看起来像这样(这部分很好):
@code {
IEnumerable<IDictionary<string, object>> data;
int count;
bool isLoading;
async Task LoadData(LoadDataArgs args)
{
isLoading = true;
var uri = new Uri("https://services.radzen.com/odata/Northwind/Employees")
.GetODataUri(filter: args.Filter, top: args.Top, skip: args.Skip, orderby: args.OrderBy, count: true);
var response = await new HttpClient().SendAsync(new HttpRequestMessage(HttpMethod.Get, uri));
var result = await response.ReadAsync<ODataServiceResult<IDictionary<string, object>>>();
data = result.Value.AsODataEnumerable();
count = result.Count;
isLoading = false;
}
}
在下拉菜单上,我想显示员工,但无法访问它(data =“@data.employee.id” is不正确,不确定要放入什么来使其正常工作)。
<RadzenDropDown Data="@data.EmployeeID" TextProperty="EmployeeID" ValueProperty="EmployeeID" Name="Dropdown1" TValue="string">
</RadzenDropDown>
谢谢!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
问题是数据属性是:
应该是:
因此,您可以对员工类属性进行审议。
The problem is that the Data Property is:
It should be:
So then you can acess to Employee class properties.
参加这个探险,您会在文章末尾找到整个课程
appdomain.currentdomain.currentdomain.definedynemicalsiCAssembly
.DEDEDINEDYNAGINICASSEMBLY (为了使用.NET Core和.NET 5+)页面的示例代码。您将在字典上循环到t.getProperty(“ userId”)。setValue(...
@代码
{
字符串值{get;放; }
列表data = new();
保护覆盖异步任务onInitializedAsync()
{
myclassbuilder mcb =新的myclassbuilder(“ clsuser”);
var myclass = mcb.createobject(new String [4] {“ userId”,“ username”,“ ofername”,“生日”,“位置”},新类型[4] {typeof(string),typeof(string),typeof(typeof(dateTime)) ,typeof(string)});
type t = myClass.getType();
var obj = activator.createinstance(t);
t.getProperty(“ userId”)。setValue(obj,“ 34”,null);
t.getProperty(“用户名”)。setValue(obj,“ albert”,null);
T.GetProperty(“生日”)。SetValue(OBJ,New DateTime(1976,3,14),null);
t.getProperty(“位置”)。SetValue(obj,“ krk”,null);
data.Add(obj);
}
}
Take this tutrial, you'll find the whole class in the end of the article
https://www.c-sharpcorner.com/UploadFile/87b416/dynamically-create-a-class-at-runtime/#fromHistory
AppDomain.CurrentDomain.DefineDynamicAssembly
must be changed toAssemblyBuilder.DefineDynamicAssembly
(in order to work with .net core and .net 5+)Example Code of the page. You'll loop on your Dictionary to t.GetProperty("UserID").SetValue(...
@code
{
string value { get; set; }
List data = new();
protected override async Task OnInitializedAsync()
{
MyClassBuilder MCB = new MyClassBuilder ("ClsUser");
var myclass = MCB.CreateObject(new string[4] { "UserID", "Username", "Birthday", "Location" }, new Type[4] { typeof(string), typeof(string), typeof(DateTime), typeof(string) });
Type t = myclass.GetType();
var obj = Activator.CreateInstance(t);
t.GetProperty("UserID").SetValue(obj, "34", null);
t.GetProperty("Username").SetValue(obj, "Albert", null);
t.GetProperty("Birthday").SetValue(obj, new DateTime(1976, 3, 14), null);
t.GetProperty("Location").SetValue(obj, "KRK", null);
data.Add(obj);
}
}