日期:2014-05-16  浏览次数:20317 次

如何把Ext.data.store里的数据一次性用JSON传给后台(添加了后台解析部分)
前台部分很简单:
首先定义一个数组,用来储存STORE里的值。
之后利用store自带的each遍历方法把数组填满。
最后建一个ajax请求传送到后台即可。
var lstAddRecord=new Array();
store.each(function(record) {
      lstAddRecord.push(record.data);
});
Ext.Ajax.request({
    url: 'function/rivaldata/rivalDataAction.do?tag=add',
    params: {strJson:Ext.encode(lstAddRecord)}
});


后台解析部分:
主要是利用了JSON-Lib包,实现了关键功能。
 String strJson=request.getParameter("strJson");
  JSONArray js=JSONArray.fromObject(strJson);
  JSONObject jo=null;
  Iterator it=js.iterator();
  while(it.hasNext()){
       jo=(JSONObject)it.next();
       //follow codes are get the value :)
       String goodId=jo.getString("goodId");
       Double goodsPrice=jo.getDouble("goodsPrice");
       //ok, to do something use the vaules:)
       System.out.println("the goodId is :"+goodId);
  }