我目前正在使用ExtJs 3.3.1作为前端制作应用程序。后端是.NET 4平台,而MVC则用于服务器端。这意味着数据一旦被请求就由控制器动作返回。ExtJs 4.0与自定义字段记录的数据绑定
我的雇主目前在同一个数据库上请求一个全新的应用程序,我打算切换到该应用程序的最高版本的ExtJs。数据处理的方式完全不同,但似乎整个数据模型都是在Javascript文件中重建的。
一个很好的例子是一个显示维护工作的网格面板。每项维护工作都有许多任务完成,许多任务未完成。接下来,一条记录可能会有下一个计划维护工作的日期。目前 - 使用ExtJs 3.3.1 - 记录在服务器上创建并作为JSON发送给客户端。数据存储/ dataproxy/gridpanel几乎没有什么可做,除了显示它。总结完成/未完成的任务在服务器端完成。
这些任务不是模型的一部分,它们是在网格面板请求数据时由服务器创建的。 ExtJs 4.0是如何完成的?我是否需要将商店连接到返回数据的控制器操作,显然该商店是只读的?我需要在客户端的“维护工作”模型中定义这些总结吗?或者这是一种绕过Javascript文件中创建的模型的情况?
我一直没能找到太多的东西,几乎所有的例子都使用与数据库表对应的模型。数据存储可能非常简单,但我需要的不仅仅是一张表中的记录。
下面的代码是现有的ExtJs 3.3.1代码,演示了当前的数据处理方式。
var visitReportStore = new Ext.data.Store({
id: 'id',
proxy: new Ext.data.HttpProxy({ url: '<%= Url.Action("ListVisitReports", "VisitReport") %>' }),
reader: new Ext.data.JsonReader(
{
totalProperty: 'records',
idProperty: 'Id',
root: 'rows'
},
[
{ name: 'Id' },
{ name: 'Employee' },
{ name: 'CreationDate' },
{ name: 'VisitDate' },
{ name: 'TicketId' },
{ name: 'ProposalId' },
{ name: 'ProposalNr' },
{ name: 'RelationId' },
{ name: 'Relation' },
{ name: 'HoursOsab' },
{ name: 'HoursInvoice' },
{ name: 'HoursNonInvoice' },
{ name: 'HoursTotal' },
{ name: 'Action' }
]
),
remoteSort: true,
baseParams: { proposalId: <%= Model.Id %> },
autoLoad: true
});
var visitReportStore = new Ext.data.Store({
id: 'id',
proxy: new Ext.data.HttpProxy({ url: '<%= Url.Action("ListVisitReports", "VisitReport") %>' }),
reader: new Ext.data.JsonReader(
{
totalProperty: 'records',
idProperty: 'Id',
root: 'rows'
},
[
{ name: 'Id' },
{ name: 'Employee' },
{ name: 'CreationDate' },
{ name: 'VisitDate' },
{ name: 'TicketId' },
{ name: 'ProposalId' },
{ name: 'ProposalNr' },
{ name: 'RelationId' },
{ name: 'Relation' },
{ name: 'HoursOsab' },
{ name: 'HoursInvoice' },
{ name: 'HoursNonInvoice' },
{ name: 'HoursTotal' },
{ name: 'Action' }
]
),
remoteSort: true,
baseParams: { proposalId: <%= Model.Id %> },
autoLoad: true
});
public class VisitReportListItem : ListItem<VisitReportListItem>
{
public int Id { get; set; }
public string Employee { get; set; }
public DateTime CreationDate { get; set; }
public DateTime VisitDate { get; set; }
public int? TicketId { get; set; }
public int? ProposalId { get; set; }
public string ProposalNr { get; set; }
public int RelationId { get; set; }
public string Relation { get; set; }
public int? MaintenanceId { get; set; }
public string Maintenance { get; set; }
public decimal? HoursOsab { get; set; }
public decimal? HoursInvoice { get; set; }
public decimal? HoursNonInvoice { get; set; }
public decimal? HoursTotal { get; set; }
public string Action { get; set; }
}
模型与Ext3中的“记录”类相同。它可以像你想要的那样复杂或简单。事实上,您可以将字段名称数组复制到模型中,然后完成。 – 2014-08-29 10:50:24