我正在使用 jqGrid 并想使用 Coldfusion 的 ajax 返回来构建 colModel 数组。
当我像下面这样在客户端上创建数组 cm 时,它可以工作。
function subTab(obj,id,tab){
var param={id:id,tab:tab}
http('POST','cfc/view/'+obj+'.cfc?method=view',subTab_RTN,param);
}
function subTab_RTN(obj){
$("#detail").html(obj.html);
if(obj.grid.display){
var cm;
switch(obj.grid.tab){
case "docs":
cm=[{name:'contactID',index:'contactID',hidden:true},
{name:'docName',index:'docName',width:200,label:'Document Name'},
{name:'docType',index:'docType',width:200,label:'Document Type'},
{name:'campaign',index:'campaign',width:200,label:'Campaign'},
{name:'campaignCode',index:'campaignCode',width:125,label:'Campaign Code'},
{name:'campaignType',index:'campaignType',width:125,label:'Campaign Type'},
{name:'downloadDate',index:'downloadDate',width:125,label:'Download Date',formatter:'date'}];
break;
}
$("#subTabGridTbl").jqGrid({
url:obj.grid.url,
datatype: "json",
colModel:cm,
...
但是,我更愿意在服务器上创建数组,例如:
<cfset rtn.grid.cols="[{name:'contactID',index:'contactID',hidden:true},
{name:'docName',index:'docName',width:200,label:'Document Name'},
{name:'docType',index:'docType',width:200,label:'Document Type'},
{name:'campaign',index:'campaign',width:200,label:'Campaign'},
{name:'campaignCode',index:'campaignCode',width:125,label:'Campaign Code'},
{name:'campaignType',index:'campaignType',width:125,label:'Campaign Type'},
{name:'downloadDate',index:'downloadDate',width:125,label:'Download Date',formatter:'date'}]" />
然后使用返回的 obj (obj.grid.cols) 构建数组。
谢谢你的帮助。加里