Dextop C#模型中的计算字段

时间:2011-09-15 08:11:37

标签: c# extjs4

在Dextop C#模型中创建计算字段的最佳方法是:

根据FirstName和LastName字段创建FullName字段的值,类似于ExtJ中的以下内容:

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'}
]
});

当用户在表单上的FirstName或LastName字段中键入时,实时更新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; }
}

1 个答案:

答案 0 :(得分:1)

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

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

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