刚实习接触项目,在积累经验,欢迎交流
前段时间遇到了json解析以及datagrid列重复问题,特意记录下来,便于以后查看。
JS代码:
function search(){
$('#gridList').datagrid({
url: sy.contextPath + '/integratedSearchEnterprise/findJoinTrade',
method:'post',
queryParams: $("#searchForm").serializeJson(),
pagination: true,
striped: true,
nowrap:false,
singleSelect: false,
fit : true,
collapsible : true,
loading:true,
loadMsg:loadMsgs,
fitColumns:true,
showHeader:true,
pageNumber:1,
pageSize:pageSizes,
pageList:pageLists,
rownumbers:true,
idField:'id',
sortName:'id',
sortOrder:'desc',
columns:[[
{field:'basenumber', title:'企业编号', align:'left', sortable:'true', width:'5%'},
{field:'cnname', title:'业户名称', align:'left', sortable:'true', width:'22%'},
{field:'enterprisetrade',title:'经营范围', align:'left', sortable:'true', width:'5%',
formatter: function(value){
return value[0].scopename;
}},
{field:'opendate', title:'开业日期', align:'left', sortable:'true', width:'10%'},
{field:'businessstatus', title:'经营状态', align:'left', sortable:'true', width:'10%',
formatter: function(val){
return businessstatusMap[val];
}},
{field:'manageclass', title:'业户类别', align:'left', sortable:'true', width:'10%',
formatter: function(val){
return enterpriseTypeMap[val];
}},
{field:'enterprisetrade1', title:'托管企业', align:'left', sortable:'true', width:'23%',
formatter: function(value,rowData,rowIndex){
return rowData.enterprisetrade[0].trusteeId;
}},
{field:'enterprisetrade2', title:'管理机构', align:'left', sortable:'true', width:'7%',
formatter: function(value,rowData,rowIndex){
return enterpriseManageRence[rowData.enterprisetrade[0].manageragence];
}},
{field:'id', title:'操作', align:'left', width:'8%',
formatter: function(value, row, index){
var v = '';
v += viewBtn(row.id);
return v;
}}
]],
onLoadError: function(){
$.messager.alert(warningTitle, errorMsgs, 'warning');
closeProgress();
},onBeforeLoad : function(param) {
startProgress();
},
onLoadSuccess : function(data) {
clearGrid($('#gridList'));
closeProgress();
}
});
}
JSON值
{
"total" : 5155,
"rows" : [ {
"id" : "{FFFD1217-EAC3-4F13-D0A9-5F1D759C3796}",
"cnname" : "上海黄浦区山青客运出租服务社",
"enname" : null,
"abbreviation" : null,
"organizationcode" : null,
"economictype" : "400",
"legalperson" : "史国定",
"legalpersondocumenttype" : null,
"legalpersondocumentnum" : null,
"phonenumber" : null,
"fax" : null,
"businesslicense" : null,
"registereddistrict" : null,
"registeredaddress" : "上海市黄浦区梅家街40弄3号",
"registeredpostalcode" : null,
"taxlicense" : null,
"statisticslicense" : null,
"complaintcall" : null,
"website" : null,
"isremove" : 0,
"addoperation" : null,
"addtime" : "2014-11-14 10:25:41",
"updateoperation" : null,
"updatetime" : null,
"manageclass" : "2",
"licensenumber" : null,
"recordno" : null,
"transitattachclass" : null,
"parentbody" : null,
"parentvalidity" : null,
"parentlicensenumber" : null,
"parentname" : null,
"parentscope" : null,
"parentlssuer" : null,
"nativeplace" : null,
"foreignlicensenumber" : null,
"opendate" : "2005-04-08 00:00:00",
"cancellationdate" : null,
"basenumber" : "D006",
"busbasenumber" : null,
"businessstatus" : "206",
"alonedrive" : "Y",
"oldlicensenumber" : null,
"oldrecordno" : null,
"businesslicensedate" : "2005-04-08 00:00:00",
"taxlicensedate" : null,
"registerrmb" : null,
"email" : null,
"legalpersonphone" : null,
"registerusd" : null,
"enterprisetrade" : [ {
"id" : "07CB914D8A4AFCC1E0531629A8C05B8E",
"basicId" : "{FFFD1217-EAC3-4F13-D0A9-5F1D759C3796}",
"scopeid" : "21000",
"scopecode" : "21000",
"scopename" : "出租",
"tradestatus" : "206",
"registrationauthority" : null,
"approvalauthority" : null,
"manageragence" : "310000",
"managerdepartment" : null,
"operatedistrict" : "310101",
"operateaddress" : "上海市黄浦区梅家街40弄3号",
"operatepostalcode" : 200072,
"dutyperson" : null,
"dutypersontel" : null,
"dutypersonmobile" : null,
"dutypersonfax" : null,
"dutypersonpostalcode" : null,
"operateperiod" : null,
"beginvaliddate" : "2005-04-08 00:00:00",
"endvaliddate" : null,
"recordoperateperiod" : null,
"recordbeginvaliddate" : null,
"recordendvaliddate" : null,
"nature" : null,
"trusteeId" : "{5BDB512D-E263-D47D-F75B-0002A83B5ED0}",
"professional" : null,
"professionlevel" : null,
"specialtynum" : null,
"ordinarynum" : null,
"basenumber" : null,
"enterprisetype" : null,
"fixedassets" : null,
"currentassets" : null,
"trainarea" : null,
"trainroad" : null,
"copperno" : null,
"fsshop" : null,
"cargotype" : null,
"opendate" : "2005-04-08 00:00:00",
"cancellationdate" : null,
"cancellationreason" : null,
"cancellationtype" : null,
"addoperation" : null,
"addtime" : "2014-11-14 13:04:54",
"updateoperation" : null,
"updatetime" : null,
"isremove" : 0,
"creditrate" : null,
"remarks" : null,
"tradeId" : "201"
} ]
}]
}
一切的重点,都要先观察JSON的格式,大括号,中括号,以及其中的并列关系,都需要弄清楚,之后才能做具体的解析。
以及datagrid中列重复,将随便写一个不存在的列名,然后调用对应方法即可。