ExtJS 4 DirectStore post参数的变化以及应对方法
2011-05-28 21:51
597 查看
还是Ext4,还是direct,这次是发送到后台参数的变化问题。
在Ext3中,继承Ext.data.DirectStore需要通过sortInfo属性指定排序字段和排序方法,通过paramOrder指定传入后台参数的顺序,例如:
参数发送的方式是分别使用字符串post到后台,这是firebug相应信息:
后台通过设定好的参数顺序接受对应参数(均为string类型):
在Ext4的Ext.data.DirectStore中取消sortInfo和paramOrder属性,改为继承自Ext.util.MixedCollection的sorters。但是无论是官方example还是direct的example,都没有相应的说明和例子,那首先按文档把js写好:
注意里面的sorters是MixedCollection类型,可以写多个(用于支持多排序)
测试通过,跟踪一下firebug看看,post过去的是这个:
貌似也是MixedCollection类型,后台通过Dictionary<string, object>接受,最终调试成功的代码为:
可以通过object[]数组提取各个排序信息,也可以提取start、page、limit参数用于分页。
继续研究Ext4,变化真的不小。
在Ext3中,继承Ext.data.DirectStore需要通过sortInfo属性指定排序字段和排序方法,通过paramOrder指定传入后台参数的顺序,例如:
var store = new Ext.data.DirectStore({ remoteSort: true, directFn: Sample.Grid.PagingLoad, paramOrder: ['sort', 'dir', 'start', 'limit'], idProperty: 'id', totalProperty: 'total', root: 'data', sortInfo: { field: 'name', direction: 'ASC' }, fields: [{ type: 'int', name: 'id' }, 'name', { type: 'int', name: 'employees' },{ type: 'float', name: 'turnover' },{ type: 'date', name: 'started', dateFormat: 'c' }] });
参数发送的方式是分别使用字符串post到后台,这是firebug相应信息:
后台通过设定好的参数顺序接受对应参数(均为string类型):
[DirectMethod] public CompanySerializer PagingLoad(string order, string direction, long start, long limit) { CompanyCollection coll = new CompanyCollection(); coll.OrderField = order; coll.OrderDirection = direction.ToLower() == "desc" ? CompanyCollection.Direction.DESC : CompanyCollection.Direction.ASC; return new CompanySerializer(coll, Convert.ToInt32(start), Convert.ToInt32(limit)); }
在Ext4的Ext.data.DirectStore中取消sortInfo和paramOrder属性,改为继承自Ext.util.MixedCollection的sorters。但是无论是官方example还是direct的example,都没有相应的说明和例子,那首先按文档把js写好:
var store = Ext.create('Ext.data.DirectStore', { autoLoad: true, autoSave: true, remoteSort: true, api: { create: MyApp.FileAction.Create, read: MyApp.FileAction.Load, update: MyApp.FileAction.Update, destroy: MyApp.FileAction.Destroy }, writer: new Ext.data.JsonWriter({ encode: false, writeAllFields: true }), idProperty: 'id', totalProperty: 'total', root: 'data', sorters: [{ property: 'datetimeCreated', direction: 'DESC' }], fields: ['title', 'classId',{ name: 'datetimeCreated', mapping: 'datetimeCreated', type: 'date', dateFormat: 'timestamp' }, 'docAbstract','typeId'] });
注意里面的sorters是MixedCollection类型,可以写多个(用于支持多排序)
测试通过,跟踪一下firebug看看,post过去的是这个:
貌似也是MixedCollection类型,后台通过Dictionary<string, object>接受,最终调试成功的代码为:
[DirectMethod] public FileInfoSerializer Load(Dictionary<string,object> arg) { object[] sorters = (object[])arg["sort"]; Dictionary<string, object> sorter = (Dictionary<string, object>)sorters[0]; FileInfoCollection coll = new FileInfoCollection(); coll.OrderField = sorter["property"].ToString(); coll.OrderDirection = sorter["direction"].ToString().ToLower() == "desc" ? FileInfoCollection.Direction.DESC : FileInfoCollection.Direction.ASC; return new FileInfoSerializer(coll); }
可以通过object[]数组提取各个排序信息,也可以提取start、page、limit参数用于分页。
继续研究Ext4,变化真的不小。
相关文章推荐
- Web APi之捕获请求原始内容的实现方法以及接受POST请求多个参数多种解决方案(十四)
- Ajax访问不断变化的session的值不同步解决方法以及HTTP协议中的GET、POST的区别
- ajax中post方法传参数,会丢失&,%,+',要转义
- C# Windows Api的一些方法 封装 以及 常用参数 .
- hibernate常用的接口和类的方法以及持久化对象的状态变化
- 【on】动态标签绑定事件 以及动态删除的参数的变化
- 复习一下基础:'C# 值类型和引用类型 以及作为方法参数的区别'
- [技术]window.open的使用方法以及参数说明
- ajax xmlhttp下open方法POST、GET参数的区别
- RESTClient插件POST方法传递参数
- 获得方法参数名的多种方法以及javassit的bug
- c# webapi POST 参数解决方法
- 设计中应对变化的方法
- $.getJSON() 方法第二个参数的使用以及后台servlet如何处理。
- Thin的DateChooser代码学习(关于js的函数参数为一个完整的函数以及“对象不支持此属性或方法”错误的解决)(原创,转载请声明)
- javascript弹出窗口 window.open使用方法以及参数说明分析篇
- c#方法中调用参数的值传递方式和引用传递方式,以及ref与out的区别
- bootbox自定义dialog、confirm、alert样式,以及基本设置方法setDefaults中可用参数
- jquery 获取url 参数方法 以及 解决url中文问题
- Java之发送带参数的Post请求方法