具有相同属性名称的 Telerik Grid

发布于 2024-11-05 00:34:50 字数 1472 浏览 1 评论 0原文

我正在开发一个医疗应用程序,其中网格需要显示 ICD 描述及其相关的 HCC 类别描述。 ICD 和 HCC 类型如下所示:

public class ICD {
    public String Code { get; set; }

    public String Description { get; set; }

    public HCC HCC { get; set; }
}

public class HCC {
    public Int32 ID { get; set; }

    public String Description { get; set; }
}

当我将 Telerik MVC 扩展网格绑定到 ICD 对象列表时,我将像这样设置列:

this.Html.Telerik().Grid(this.Model.ICDs)
    .Name("ICDGrid")
    .DataKeys(keys => keys.Add(icd => icd.Code))
    .DataBinding(binding => {
        binding.Ajax().Select(this.Model.AjaxSelectMethod);
        binding.Ajax().Update(this.Model.AjaxUpdateMethod);
    })
    .Columns(columns => {
        columns.Bound(icd => icd.ICDType.Name).Title("ICD 9/10");
        columns.Bound(icd => icd.Code);
        columns.Bound(icd => icd.Description);
        columns.Bound(icd => icd.HCC.Description).Title("HCC Category")
        columns.Command(commands => commands.Delete()).Title("Actions").Width(90);
    })
    .Editable(editing => editing.Mode(GridEditMode.InCell).DefaultDataItem(new ICD()))
    .ToolBar(commands => {
        commands.Insert();
        commands.SubmitChanges();
    })
    .Sortable()
    .Filterable()
    .Pageable(paging => paging.PageSize(12))
    .Render();

问题是 ICD 和 HCC 都有名为“Description”的属性,并且我对此无法控制。有没有办法告诉 Telerik 在它生成的 JavaScript 中将它们称为不同的东西?像 ICDDescription 和 HCCDescription 之类的东西?

I'm working on a medical application where a grid needs to display the ICD description as well as its associated HCC category description. The ICD and HCC types look like this:

public class ICD {
    public String Code { get; set; }

    public String Description { get; set; }

    public HCC HCC { get; set; }
}

public class HCC {
    public Int32 ID { get; set; }

    public String Description { get; set; }
}

When I bind the Telerik MVC extensions grid to a list of ICD objects, I'm setting up the columns like so:

this.Html.Telerik().Grid(this.Model.ICDs)
    .Name("ICDGrid")
    .DataKeys(keys => keys.Add(icd => icd.Code))
    .DataBinding(binding => {
        binding.Ajax().Select(this.Model.AjaxSelectMethod);
        binding.Ajax().Update(this.Model.AjaxUpdateMethod);
    })
    .Columns(columns => {
        columns.Bound(icd => icd.ICDType.Name).Title("ICD 9/10");
        columns.Bound(icd => icd.Code);
        columns.Bound(icd => icd.Description);
        columns.Bound(icd => icd.HCC.Description).Title("HCC Category")
        columns.Command(commands => commands.Delete()).Title("Actions").Width(90);
    })
    .Editable(editing => editing.Mode(GridEditMode.InCell).DefaultDataItem(new ICD()))
    .ToolBar(commands => {
        commands.Insert();
        commands.SubmitChanges();
    })
    .Sortable()
    .Filterable()
    .Pageable(paging => paging.PageSize(12))
    .Render();

The problem is that both ICD and HCC have properties named "Description", and I have no control over that. Is there a way to tell Telerik to call them different things in the JavaScript it generates? Something like ICDDescription and HCCDescription?

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

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

发布评论

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

评论(1

爱她像谁 2024-11-12 00:34:50

目前您无法为属性添加别名。您可以做的是创建一个 ViewModel 对象,其中的属性被唯一命名。然后将网格绑定到 ViewModel 对象。下面是一个代码片段:

public class ICDViewModel
{
   public string Description
   {
      get;
      set;
   }
   public string HCCDescription
   {
      get;
      set;
   }
   // The rest of the properties of the original ICD class
}

然后您需要更改 Model.ICDs 的类型以使用 ICDViewModel。您可以使用 Select 扩展方法将 ICD 映射到 ICDViewModel:

Model.ICDs = icds.Select(icd => new ICDViewModel 
{ 
   Description = icd.Description,
   HCCDescription = icd.HCC.Description
   /* set the rest of the ICD properties */
});

Currently you cannot alias the properties. What you can do is create a ViewModel object with where the properties are named uniquely. Then bind the grid to the ViewModel object. Here is a code snippet:

public class ICDViewModel
{
   public string Description
   {
      get;
      set;
   }
   public string HCCDescription
   {
      get;
      set;
   }
   // The rest of the properties of the original ICD class
}

Then you need to change the type of Model.ICDs to use ICDViewModel. You can use the Select extension method to map ICD to ICDViewModel:

Model.ICDs = icds.Select(icd => new ICDViewModel 
{ 
   Description = icd.Description,
   HCCDescription = icd.HCC.Description
   /* set the rest of the ICD properties */
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文