来自外部API的动态数据的Radzen Blazor下拉列表

发布于 2025-01-25 18:26:58 字数 1063 浏览 3 评论 0 原文

我正在从外部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>

谢谢!

I'm getting data from an external API and the code looks like this (this part is fine):

@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;
    }
}

On the dropdown menu I want to display the EmployeeID, but cannot access it (the Data="@data.Employee.ID" is incorrect and not sure what to put in there to make it work).

<RadzenDropDown Data="@data.EmployeeID" TextProperty="EmployeeID" ValueProperty="EmployeeID" Name="Dropdown1" TValue="string">
            </RadzenDropDown>

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

岁月苍老的讽刺 2025-02-01 18:26:58

问题是数据属性是:

 IEnumerable<IDictionary<string, object>> data;

应该是:

IEnumerable<Employee>data;

因此,您可以对员工类属性进行审议。

<RadzenDropDown Data="@data.EmployeeID" TextProperty="EmployeeID" ValueProperty="EmployeeID" Name="Dropdown1" TValue="Employee">
            </RadzenDropDown>

The problem is that the Data Property is:

 IEnumerable<IDictionary<string, object>> data;

It should be:

IEnumerable<Employee>data;

So then you can acess to Employee class properties.

<RadzenDropDown Data="@data.EmployeeID" TextProperty="EmployeeID" ValueProperty="EmployeeID" Name="Dropdown1" TValue="Employee">
            </RadzenDropDown>
埋葬我深情 2025-02-01 18:26:58
  1. 参加这个探险,您会在文章末尾找到整个课程


  2. appdomain.currentdomain.currentdomain.definedynemicalsiCAssembly .DEDEDINEDYNAGINICASSEMBLY (为了使用.NET Core和.NET 5+)

  3. 页面的示例代码。您将在字典上循环到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);
    }
    }

  1. 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

  2. AppDomain.CurrentDomain.DefineDynamicAssembly must be changed to AssemblyBuilder.DefineDynamicAssembly (in order to work with .net core and .net 5+)

  3. 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);
    }
    }

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文