Dextop C# 模型中的计算字段
在 Dextop C# 模型中创建计算字段的最佳方法是什么:
根据 FirstName 和 LastName 字段创建 FullName 字段的值,类似于 ExtJs 中的以下内容:
function fullName(v, record){
return record.name.last + ', ' + record.name.first;
}
Ext.define('Contact', {
extend: 'Ext.data.Model',
fields: [
{name: 'fullname', convert: fullName},
{name: 'firstname', mapping: 'name.first'},
{name: 'lastname', mapping: 'name.last'}
]
});
实时更新 FullName 字段为用户正在表单上的名字或姓氏字段中输入。
C#模型代码:
[DextopModel]
[DextopGrid]
[DextopForm]
class MyModel
{
[DextopModelId]
[DextopGridColumn(width = 50, readOnly=true)]
public int Id { get; set; }
[DextopFormField(anchor = "0", allowBlank = false, labelAlign = "top")]
[DextopGridColumn()]
public String FirstName { get; set; }
[DextopFormField(anchor = "0", allowBlank = false, labelAlign = "top")]
[DextopGridColumn()]
public String LastName { get; set; }
[DextopFormField(anchor="0", readOnly=true, labelAlign = "top")]
[DextopGridColumn(flex=1)]
public String FullName { get; set; }
}
What is the best way to create a calculated field in a Dextop C# model that does the following:
Creates the value for the FullName field based both the FirstName and LastName fields, similar to the following in ExtJs:
function fullName(v, record){
return record.name.last + ', ' + record.name.first;
}
Ext.define('Contact', {
extend: 'Ext.data.Model',
fields: [
{name: 'fullname', convert: fullName},
{name: 'firstname', mapping: 'name.first'},
{name: 'lastname', mapping: 'name.last'}
]
});
Updates the FullName field in realtime as the user is typing in either the FirstName or LastName fields on the form.
C# model code:
[DextopModel]
[DextopGrid]
[DextopForm]
class MyModel
{
[DextopModelId]
[DextopGridColumn(width = 50, readOnly=true)]
public int Id { get; set; }
[DextopFormField(anchor = "0", allowBlank = false, labelAlign = "top")]
[DextopGridColumn()]
public String FirstName { get; set; }
[DextopFormField(anchor = "0", allowBlank = false, labelAlign = "top")]
[DextopGridColumn()]
public String LastName { get; set; }
[DextopFormField(anchor="0", readOnly=true, labelAlign = "top")]
[DextopGridColumn(flex=1)]
public String FullName { get; set; }
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
答案很简单。 Dextop 支持服务器端的计算列。更改 FullName 属性,如下面的示例所示。
作为替代方案,您可以使用 DextopModelField 属性来指定将在模型中生成的转换函数。
Answer is very simple. Dextop supports calculated columns on the server side. Change the FullName property like in the sample below.
As an alternative you can use DextopModelField attribute to specify convert function which will be generated in the model.