ext direct spring Store Modify Method
来源:互联网 发布:肉毒素 腋臭 知乎 编辑:程序博客网 时间:2024/06/05 06:37
Server
Create/Update
负责处理从DirectStore发出的创建,更新和销毁请求的方法添加注解@ExtDirectMethod(value = ExtDirectMethodType.STORE_MODIFY)。此类方法可以有一个集合类型参数或单个
对象。不能两个名称一样的方法都用@ExtDirectMethod注解。
方法的返回类型跟参数类型相同或是ExtDirectStoreResult实例。当reader配置了root属性时方法返回一个对象实例。
集合参数例子:
@ExtDirectMethod(value = ExtDirectMethodType.STORE_MODIFY) public List<Person> createOrUpdate(List<Person> newOrUpdatedPersons) { List<Person> result = Lists.newArrayList(); for (Person person : newOrUpdatedPersons) { //for example insert/update person into database //set the id attribute if it's an insert and add it to the result collection result.add(person); } return result; }
对象作为参数例子:
@ExtDirectMethod(value = ExtDirectMethodType.STORE_MODIFY) public Person createOrUpdate(Person person) { //insert or update person //set id if it's an insert return person; }
在DirectStore中的数据在服务器更新后返回。因此,服务器方法有机会通过简单的返回更改数据或什么都不返回。一个常见的用例是数据库插入后返回主键对象。
返回一个集合或是一个对象是有客户端决定的。例如如果store的autoSync设置为disabled,那么用户可以修改多条记录而不像服务器发送任何数据。当手动同步store是发送多条记
录到服务器。在这中情况服务器方法需要一个集合参数接收所有修改或插入的多行记录。在另外一中情况,如果autoSync设置的值true store 会发送修改或插入的数据到服务器端
每次用户修改或插入数据的时候,在这中情况服务器端每次只处理一个对象。一个对象方法也适用于没有store,而从Model类调用save()或destroy()的情形。
如果客户端设置了reader的root属性,服务器方法返回一个对象实例,对象实例包装为ExtDirectStoreResult。
Ext.define('Person', { extend : 'Ext.data.Model', fields : ..., proxy : { type: 'direct', api: { ... }, reader : { root : 'records' } }});@ExtDirectMethod(STORE_MODIFY)public ExtDirectStoreResult<User> create(User newUser) { //do something with newUser return new ExtDirectStoreResult<>(newUser);}
包装不是必须的,当方法返回一个集合时,Extj都能正确处理,无论reader带或不带root属性。
Destroy Ext JS 3.x
跟create和update方法相比,destroy方法只接收一个id的集合,并返回一个id的集合。
@ExtDirectMethod(value = ExtDirectMethodType.STORE_MODIFY, entryClass = Integer.class) public List<Integer> destroy(List<Integer> destroyIds) { List<Integer> deletedPersonsId = Lists.newArrayList(); for (Integer id : destroyIds) { ... deletedPersonsId.add(id); } return deletedPersonsId; }
该方法可以返回一个空的集合否决destroy请求。
Destroy Ext JS 4.x and Sencha Touch 2
在Ext JS的4.x的的destory方法运行方式发生改变,客户端发送整个对象到服务器端就像create和update方法。好像不能否决destory方法了在4.x版本中。虽然服务器端可以忽略掉
deleted请求,但如果他没重新加载数据,用户不能够在看见删除的记录了。
@ExtDirectMethod(STORE_MODIFY) public void destroy(List<User> destroyUsers) { for (User user : destroyUsers) { //delete the user from the persistent storage //or ignore the request }}
Client Ext JS 3.x
在客户端需要一个JsonWriter的实例。JsonWriter的listful的属性必须设置为true。这种方式writer会一直发送一个list到服务器,甚至虽然只有一条记录插入,更新或销毁。
encode属性必须设置为false。如果writeAllFields设置为true,记录的所有字段都会发送到服务器,如果设置为false,只有改变的字段发送到服务器。
var writer = new Ext.data.JsonWriter( { writeAllFields: true, listful: true, encode: false });
在API中配置create/read/update/delete方法。
var directStore = new Ext.data.DirectStore( { id: 'directStore', paramsAsHash: true, root: 'records', totalProperty: 'total', autoLoad: false, autoSave: true, successProperty: 'success', fields: ['id', 'firstName', 'lastName'], remoteSort: true, idProperty: 'id', writer: writer, api: { read: personAction.load, create: personAction.createOrUpdate, update: personAction.createOrUpdate, destroy: personAction.destroy } });
Client Ext JS 4.x and Sencha Touch 2
在Extjs 4.x中配置DirectStore发生一些变化,虽然仍然可以在DirectStore配置一切属性,但首选的方式是在模型类中配置代理对象。
Ext.define('Person', { extend : 'Ext.data.Model', fields : [ 'id', 'firstName', 'lastName' ], proxy : { type: 'direct', api: { read: personAction.load, create: personAction.createOrUpdate, update: personAction.createOrUpdate, destroy: personAction.destroy }, reader : { root : 'records' } }});var store = Ext.create('Ext.data.Store', { autoLoad: false, autoSave: true, model : 'Person'});
Examples
http://demo.rasc.ch/eds/extjs3/grid.html
http://demo.rasc.ch/eds/extjs42/rowedit.html
http://demo.rasc.ch/eds/extjs42/roweditpaging.html
http://demo.rasc.ch/eds/extjs41/rowedit.html
http://demo.rasc.ch/eds/extjs41/roweditpaging.html
- ext direct spring Store Modify Method
- ext direct spring Store Read Method
- ext direct spring Simple Method
- ext direct spring Polling Method
- ext direct spring sse method
- Ext Direct Spring Tree Load Method
- ext direct spring Form Method and @JsonView
- ext direct spring Simple Named Parameter Method 命名参数方法
- ext direct spring 介绍
- ext direct spring Api
- ext direct spring Configuration
- 【ExtJS】Cannot modify ext-empty-store
- 配置 ext direct spring Spring XML
- ext direct spring Spring Java Config
- ext direct spring Maven set up(配置)
- Ext.Direct
- ext direct spring Model Generator and Generator APT
- ext store
- js实现html表格导出到excel
- 对象创建过程/初始化顺序
- 青春谢幕时的开场
- 设置tomcat为支持中文url
- 推荐:2014年中国政府投资项目工程建设代建单位管理中心工程项目管理信息化GOVPM解决方案
- ext direct spring Store Modify Method
- 大家心目中项目管理辅助软件系统是个什么样子?
- linux测试硬盘读写速度
- 直接拿来用!最火的Android开源项目(三部完整版)
- 数据去重的磁盘索引瓶颈
- IOS的通知中心
- ubuntu默认root密码
- InvocationHandler+工厂设计模式 实现动态代理
- 西电“可展开天线”项目获2013年度国家科学技术进步二等奖