Dextop C# 模型中的计算字段

发布于 2024-12-04 13:51:27 字数 1046 浏览 0 评论 0原文

在 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 技术交流群。

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

发布评论

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

评论(1

万劫不复 2024-12-11 13:51:27

答案很简单。 Dextop 支持服务器端的计算列。更改 FullName 属性,如下面的示例所示。

[DextopFormField(anchor="0", readOnly=true, labelAlign = "top")] 
[DextopGridColumn(flex=1)]    
public String FullName { get { return String.Format("{0} {1}", FirstName, LastName); } }   

作为替代方案,您可以使用 DextopModelField 属性来指定将在模型中生成的转换函数。

Answer is very simple. Dextop supports calculated columns on the server side. Change the FullName property like in the sample below.

[DextopFormField(anchor="0", readOnly=true, labelAlign = "top")] 
[DextopGridColumn(flex=1)]    
public String FullName { get { return String.Format("{0} {1}", FirstName, LastName); } }   

As an alternative you can use DextopModelField attribute to specify convert function which will be generated in the model.

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