具有相同属性名称的 Telerik Grid
我正在开发一个医疗应用程序,其中网格需要显示 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
目前您无法为属性添加别名。您可以做的是创建一个 ViewModel 对象,其中的属性被唯一命名。然后将网格绑定到 ViewModel 对象。下面是一个代码片段:
然后您需要更改 Model.ICDs 的类型以使用 ICDViewModel。您可以使用
Select
扩展方法将 ICD 映射到 ICDViewModel: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:
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: