首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > Web前端 >

editorgrid批量下传数据

2012-09-09 
editorgrid批量上传数据前台ext页面PersonRegistration Ext.extend(Ext.Panel,{personRegistrationForm:n

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的依赖包也不对,看来版本也是要兼容的

热点排行