editorgrid批量上传数据

前台ext页面
PersonRegistration = Ext.extend(Ext.Panel,{
personRegistrationForm:null,
personRegistrationGridPanel:null,
constructor:function() {
this.personRegistrationForm = new PersonRegistrationForm();
this.personRegistrationGridPanel = new PersonRegistrationGridPanel();
PersonRegistration.superclass.constructor.call(this,{
renderTo:"getLineCode",
autoWidth:true,
items:[this.personRegistrationForm,this.personRegistrationGridPanel]

});
}

});
/*****************************************************/
PersonRegistrationForm = Ext.extend(Ext.form.FormPanel,{
constructor:function() {
PersonRegistrationForm.superclass.constructor.call(this,{
id:"lineCodeForm",
height:100,
frame:true,
defaultType:"textfield",
buttonAlign:"left",
standarSubmit:true,
items:[{
name:"taxpayid",
allowBlank:false,
fieldLabel:"计算机代码"
}],
buttons:[
{
text:"保存",
handler:function() {
var storeValue = Ext.getCmp("personRegistrationGrid").getStore();
//var m = storeValue.getModifiedRecords();
var jsonarray=[];
//Ext.each(m,function(item){jsonArray.push(item.data);});
storeValue.each(function(item){
//jsonarray.push(item.get("documentsid")+","+item.get("linecode"));
jsonarray.push(item.data);
});
var result = Ext.encode(jsonarray);

/*var lineCodeForm = Ext.getCmp("lineCodeForm");
var count = storeValue.getCount();
var _rd = 0;
lineCodeForm.form.loadRecord(storeValue.getAt(0));*/



Ext.getCmp("lineCodeForm").form.submit({
url:"http://139.28.96.10:8080/scan/secure/taxcase",
method:"POST",
params:{
result:result
},
waitTitle:"提交数据",
waitMsg:"正在提交,请稍后",
success:function(form,action) {
//alert(action.result.success);
Ext.Msg.alert("提示信息","提交成功");
//Ext.getCmp("savedGrid").getStore().reload();
//Ext.getCmp("savedGrid").getView().refresh();

}
});

//Ext.getCmp("lineCodeForm").items.itemAt(1).setValue(objs);
/*Ext.getCmp("lineCodeForm").form.submit({
url:"http://139.28.96.10:8080/scan/secure/taxcase",
method:"POST",
params:{
taxpayid:"taxpayid",
bojs:objs
},
success:function(form,action) {

Ext.Msg.alert("提示信息","删除成功");*/
//Ext.getCmp("savedGrid").getStore().reload();
//Ext.getCmp("savedGrid").getView().refresh();
/*
}
});*/
}
}
]
});
}

});
/**********************************************************/
PersonRegistrationGridPanel = Ext.extend(Ext.Panel,{
personRegistrationGrid:null,
constructor:function() {
this.personRegistrationGrid = new PersonRegistrationGrid();
PersonRegistrationGridPanel.superclass.constructor.call(this,{
frame:true,
height:200,
items:[this.personRegistrationGrid]
});
}
});
/******************************************************************/
PersonRegistrationGrid = Ext.extend(Ext.grid.EditorGridPanel,{
lineCodeStore:null,
constructor:function() {
this.lineCodeStore = new LineCodeStore();
PersonRegistrationGrid.superclass.constructor.call(this,{
id:"personRegistrationGrid",
store:this.lineCodeStore,
height:200,
clicksToEdit:2,
columns:[{
header:"id",
dataIndex:"documentsid"

},{
header:"文档名称",
dataIndex:"documentsname"
},{
header:"条形码",
dataIndex:"linecode",
editor:new Ext.form.TextField({

listeners:{
blur:function(k,e){

},
keyup:function(textfield,e) {
//alert("12121");
},
specialkey:function(field,e) {
if(e.getKey()==e.ENTER) {

e.keyCode=9;
}
}
}

})
}],


viewConfig:{
forceFit:true
},
listeners:{
afteredit:function(e){


}
}

});
}
});
/********************************************************************/
LineCodeStore = Ext.extend(Ext.data.JsonStore,{
constructor:function() {
LineCodeStore.superclass.constructor.call(this,{

url:"http://139.28.96.10:8080/scan/secure/taxrelated?id=1",
storeId:"lineCodeStore",
root:"documentses",
autoLoad:true,
sortInfo:{
field:"documentsid",
direction:"asc"
},
//totalProperty:"total",
fields:[{
name:"documentsid",
mapping:"id"
},{
name:"documentsname",
mapping:"documentsname"
},{
name:"linecode",
mapping:""
}]

});
}
});
后台Action页面
public class TaxcaseAction extends ActionSupport {
//private JSONArray arr = new JSONArray();
private String[] result = null;
private Boolean success = false;
private String taxpayid;
private Taxcase taxcase;
private TaxcaseService taxcaseService;
private TaxpayerService taxpayerService;
@Override
public String execute() throws Exception {
Taxpayer taxpayer = this.taxpayerService.getTaxpayer(1);
//System.out.println(this.taxpayerService.getTaxpayer(1).getPayername());
//this.taxcase.setTaxpayer(taxpayer);
//this.taxcaseService.add(taxcase);
//System.out.println(result[0].indexOf("]"));
//String s = "{"+result[0].substring(1, 166)+"}";
JSONArray arr = JSONArray.fromObject(result[0]);//这里要注意是result[0]
System.out.println(arr.toArray());


Object[] o = arr.toArray();
for(Object obj:o) {
System.out.println(obj);
JSONObject json = (JSONObject)obj;
TaxcaseValue taxcaseValue = (TaxcaseValue)JSONObject.toBean(json,TaxcaseValue.class);
this.taxcase = taxcaseValue.gettaxcase();
this.taxcase.setTaxpayer(taxpayer);
this.taxcaseService.add(taxcase);
}
this.success = true;
return SUCCESS;
}
本来按照查询的资料前台传过来的是array,但JSONArray.fromObject不执行也不报错
后来通过Debug发现数据在[0]里面,不然JSONObject.toBean也是不执行也不报错,当然这之前json-lib的依赖包也不对,看来版本也是要兼容的
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值