在EXTJS中使用Ext.Ajax.request实现传递主从表数据
来源:互联网 发布:linux查看线程cpu 编辑:程序博客网 时间:2024/05/16 07:57
在项目的开发过程中,经常遇见在同一个formpanel中嵌套editgridpanel的情况,这个时候报存 editgridpanel 的数据不外乎就两种:及时保存和最后批量保存。
及时保存 对后台的交互太多,和数据库打交道过于频繁,这种方式个人觉得是不可取的。
最后批量保存 在保存之前可以对数据进行任意修改,直到认为满意为止在保存,保存的时候将主表、从表数据一起提交给后台。
本文采用的方式是:ssh+extjs,extjs通过Ext.Ajax.request 将数据以json的方式传递给后台。
<code>
var currentStockGoods = f.getFieldValueAsJson('currentStockGoods.');
var p = detailgrid.store.getRange();
var products = new Array();
for (var i = 0; i < p.length; i++)
products.push(p[i].data);
currentStockGoods.products = products;
var myobj = {};
myobj.currentStockGoods = currentStockGoods;
var jdata = Ext.util.JSON.encode(myobj);
Ext.Ajax.request({
url : urlAction,
jsonData : jdata,
method : 'POST',
headers : {
'Content-Type' : 'application/json; charset=utf-8'
},
callback : function callbacked(options, success,
response) {
var rs = Ext.util.JSON
.decode(response.responseText);
if (rs.success) {
grid.store.reload();
} else {
f.markInvalid(rs.msgs);
}
}
});
</code>
按照这种方式需要注意的地方有:
1、必须设置
headers : { 'Content-Type' : 'application/json; charset=utf-8'} ,指定请求的Header信息。
2、设置jsonData
指定需要发送给服务器端的JSON数据。如果指定了该属性则其它的地方设置的要发送的参数值将无效
这个数据必须符合json的格式。
3、在action类中定义名为currentStockGoods 的一个实例对象,必须有set方法,currentStockGoods.products 是一个对象数组,有set方法。
4、在struts.xml 中定义 如下:
<package name="stockgoods" namespace="/bussiness/stockgoods" extends="struts-default,json-default">,以方便引用json拦截器
5、struts 配置文件中定义action的时候,定义拦截器如下:
<interceptor-ref name="json">
<param name="includeProperties">currentStockGoods</param>
</interceptor-ref>
这样在传递数据到服务器的时候,通过OGNL 利用son格式的数据 对 对象 currentStockGoods进行赋值。
6、如果需要其他的拦截器,则根据拦截器的功能添加。比如,需要添加验证拦截器,则可以再这个后面添加,因为先使用json拦截器得到对象的值,然后才验证。
<interceptor-ref name="crudStack" />
其中 crudStack定义如下:
<interceptor-stack name="crudStack">
<interceptor-ref name="params" />
<interceptor-ref name="defaultStack" />
........
</interceptor-stack>
进过以上配置后,在Action中保存数据时就可以得到从前台传递过来的主从表数据了。
- 在EXTJS中使用Ext.Ajax.request实现传递主从表数据
- ExtJs 4中 Ext.Ajax.request提交实现waitMsg效果
- extjs 使用Ext.Ajax.request进行数据传输
- ExtJs Ext.Ajax.request提交实现waitMsg效果
- ExtJS中Ext.Ajax.request与form1.getForm().submit
- ExtJs中Ext.Ajax.request()跟getForm().submit()得用法
- ExtJS之Ext.Ajax.request用法详解
- ExtJS之Ext.Ajax.request用法详解
- ExtJS之Ext.Ajax.request用法详解
- ExtJS之Ext.Ajax.request用法详解
- ExtJS之Ext.Ajax.request用法详解
- ExtJS之Ext.Ajax.request用法详解
- ExtJS之Ext.Ajax.request用法详解
- ExtJS -- Ext.Ajax.request 返回结果判断
- ExtJS之Ext.Ajax.request用法详解
- extjs异步刷新技术Ext.Ajax.request
- extJS提交form表单数据的方式: Ext.Ajax.request,form.submit,getEl().dom.submit()
- extjs Ext.Ajax.request 从后台得到 String 字符串 在页面显示器内容
- 计算机网络8
- 条款16:在operator =中对所有数据成员赋值
- Spring MVC入门 —— 跟开涛学SpringMVC
- 弱类型、强类型、动态类型、静态类型语言的区别是什么?
- expect example
- 在EXTJS中使用Ext.Ajax.request实现传递主从表数据
- 条款17:在operator=中检查给自己赋值的情况
- Ubuntu Server 12.04 LTS 安装 AR8161 驱动
- 第三章 构造函数,析构函数,赋值操作符
- java 中解决中文乱码问题的方法(三法)
- 心得_杂七杂八
- 非阻塞算法
- java泛型1
- Android:layout_weight的深刻理解