以下是部分代码。。主要说明的是convert和dateFamat函数
reader : new Ext.data.JsonReader({
root: "kcInfoList",
fields: [
{name: "id"},
{name: "contract", mapping:'contract.id'},
{name: "summary", mapping:'summary'},
{name: "startDate", type: 'date',dateFormat: 'Y-m-d\\TH:i:s'},
{name: "endDate", type: 'date',dateFormat: 'Y-m-d\\TH:i:s'},
{name: "supplierLinkman"},
{name: "checker", mapping:'checker', convert:function(v){
if(v)
return v.id;
else
return "";
}
},
{name: "executiveStatus", mapping:'executiveStatus', convert:function(v){
if(v)
return v.id;
else
return "";
}
},
{name: "isMeet"},
{name: "description"},
{name: "noMeetContents"},
{name: "noMeetReason"}
]
}),
从上面的例子可以看出
创建包含指定字段结构的继承自Ext.data.Record的类。静态方法。
参数:
o : Array
一个定义记录结构的字段信息数组。每个数组元素包含name,其他可选的有:mapping、type。通过它们,可以让Ext.data.Reader从一个数据对象中获取各字段的值。每个字段定义对象都可能包含如下属性:
name : String
在记录中标志一个字段的名字。它通常用于引用指定字段,例如,在定义Ext.grid.ColumnModel的dataIndex属性时,要传过去的。
mapping : String
当在Ext.data.Reader中创建记录时,如何将json对象中指定属性值映射到此字段。
type : String
字段的类型,可能值为:
auto(默认值,没有任何转化)、string、int、float、boolean、date
sortType : Mixed
Ext.data.SortTypes中的一个成员。
sortDir : String
排序方式,"ASC"或者"DESC"。
convert : Function
如果要对这个字段的值进行一些物殊处理,这时需要一个能定制的回调,用它来手工处理值。它的参数如下:
v : Mixed
通过mapping映射找到的值。已从json中取出来的。
rec : Mixed
在json中的,对应于此记录的json对象。
dateFormat : String
用于Date.parseDate函数的格式化字符串。
defaultValue : Mixed
当字段值在原数据中不存在时所取的默认值,默认为空字符串。
当然上面的代码还可以用另外的形式来表达,如:
var contentNode = new Ext.data.Record.create([
{name: 'projectId', type: 'int'},
{name: 'project', type: 'string'},
{name: 'taskId', type: 'int'},
{name: 'description', type: 'string'},
{name: 'estimate', type: 'float'},
{name: 'rate', type: 'float'},
{name: 'cost', type: 'float'},
{name: 'due', type: 'date', dateFormat:'m/d/Y'}
]);
var reader = new Ext.data.JsonReader({root:'data',id:'taskId'},contentNode);
分享到:
相关推荐
reader: new Ext.data.JsonReader({ id: 'listId', fields: tx.data.List }) }); this.conn = tx.data.conn; // Ext.sql.Proxy for managing Sqlite persistence this.proxy = new Ext.sql.Proxy(tx.data....
- `Ext.data.Record.create(fields)`: 定义数据模型。 - `Ext.data.Record.load(data, id)`: 加载数据到模型实例。 #### 27. Ext.data.DataProxy 类 (P.24) - **概述**:作为数据源的抽象接口。 - **常用方法**: ...
reader: new Ext.data.JsonReader({ id: 'listId', fields: tx.data.List }) }); this.conn = tx.data.conn; // Ext.sql.Proxy for managing Sqlite persistence this.proxy = new Ext.sql.Proxy(tx.data....
reader: new Ext.data.JsonReader({ totalProperty: 'totalProperty', root: 'root' }, ['id', 'name', 'email']) }); var grid = new Ext.grid.GridPanel({ store: store, columns: [ {header: 'ID', ...
### Ext与后台数据库交互知识点详解 #### 一、Ext中常用的类 在Ext框架中,为了更好地处理数据和用户界面的交互,引入了一系列强大的类来简化开发过程。 ##### 1.1 Ext.data `Ext.data`是Ext框架的核心模块之一...
reader: new Ext.data.JsonReader({ root: 'usrs', totalProperty: 'totalCount', successProperty: 'success', id: 'threadid', fields: [ { name: 'uid', mapping: 'uid', type: 'int' }, { name: '...
reader: new Ext.data.JsonReader({ root: 'rows', totalProperty: 'total' }) }); ``` #### 数据存储 `Store` `Store` 是 ExtJS 中用于存储数据的核心组件,支持多种类型的数据源,包括 `JsonStore`, `...
reader: new Ext.data.JsonReader({ totalProperty: "total", root: "rows", // JSON数组名称 id: "EmployeeID", fields: fields }) }); // 初始化grid var grid = new Ext.grid.GridPanel({ store: ...