论坛首页 Web前端技术论坛

如何把Ext.data.store里的数据一次性用JSON传给后台(添加了后台解析部分)

浏览 2977 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2010-04-28   最后修改:2010-05-04

前台部分

 

首先定义一个数组,用来储存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);
  }

论坛首页 Web前端技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics