Ext 可编辑表格批量提交

Ext前台页面中从store中得到修改过的数据,循环读取,拼装成 对象数组。以参数提交到Action中。 对象的属性名应与实体中的属性名称对应。

 

this.save=function(){
   var ss=Ext.getCmp("isTp_view");  
   var dd=ss.text;       
   if(dd=="是"){
    Ext.Msg.alert("提示","你已经投过票!!");
    return;
   }
   var count=this.store.modified.length;
   var aa=this.store;
   if(count==6){
    var arr="["; 
     // 循环验证
          for (var y = 0; y < count; y++) {
                var Id = aa.modified[y];
                arr+="{name:'"
                arr+=Id.data.hxr1+"',";
                arr+="xzzhw:'"+Id.data.bm+"'}";
                arr+=',';
                arr+="{name:'"
                arr+=Id.data.hxr2+"',";
                arr+="xzzhw:'"+Id.data.bm+"'}";
                 if (y <count-1)  
                  arr += ',';  
         }
         arr+="]";
             Ext.Ajax.request({
              url: 'hbrc!save.do', 
              params: {
                  data: arr
              },
              method: 'post',
              success: function(response){
                  var respText = Ext.util.JSON.decode(response.responseText);// 字符串转换为
                     // json对象
                  // 判断是否插入成功
                  if (respText.success == true) {   
                       Ext.Msg.alert('操作', respText.info);
                       isTp.reload();
                  }
                  else {
                      Ext.Msg.alert('操作', respText.error);
                  }
              },
              failure: function(response){
             
                  Ext.Msg.alert('警告', '严重错误!!!');
              },
              waitTitle: '数据提交',
              waitMsg: '数据提交中,请稍候...',
              scope: this
        }, this)
   }else{
    Ext.Msg.alert("提示","不要偷懒,全部评完!!");
    return;
   }
  };

 

 

 

下面为Action重的代码:

JSONArray arr = JSONArray.fromObject(data);
  try {
   Object[] o = arr.toArray();
   BmInfo bm=(BmInfo)request.getSession().getAttribute("bm");
   KhUsers u=(KhUsers)request.getSession().getAttribute("userInfo");
   for (Object obj : o) {
    JSONObject json = (JSONObject) obj;
    KhHbrcInfo info=(KhHbrcInfo) json.toBean(json, KhHbrcInfo.class);
      hbrcInfoService.save(info);
   }

通过JSONObject的toBean()方法即可直接把对象数组中的对象转换为实体对象。
   

你可能感兴趣的:(json,function,object,ext,url,action)