javascript - jqGrid - colNames 和 <> colModel 的长度!错误

标签 javascript jquery ajax spring-mvc jqgrid

当我使用下面的代码时,我收到“Length of colNames and <> colModel!”错误。如果 isUserGlobal 为 false,我不会收到任何错误。我使用的是jqGrid-4.5.4

receivedColModel.push({name:'NAME', index:'NAME', sortable:true});
receivedColModel.push({name:'SURNAME', index:'SURNAME', sortable:true});
receivedColModel.push({name:'AGE', index:'AGE', sortable:true});
receivedColModel.push({name:'STATUS', index:'STATUS', sortable:true});

receivedColNames.push(messageDictionary['userHistory.NAME']);
receivedColNames.push(messageDictionary['userHistory.SURNAME']);
receivedColNames.push(messageDictionary['userHistory.AGE']);
receivedColNames.push(messageDictionary['userHistory.STATUS']);

if(isUserGlobal == 'true') {
    receivedColModel.push({name:'CITY', index:'CITY', sortable:true});
    receivedColNames.push(messageDictionary['userHistory.CITY']);
}

$('#historyGrid').jqGrid({
     url:'ajax.htm',
     datatype: "json",
     mtype: "POST",
     jsonReader: { repeatitems : false, cell:"", id: "", userdata: "jsonModel", root: "rows" },
     postData:postData,
     colNames:receivedColNames,
     colModel:receivedColModel,
     .
     .
     .

顺便说一句,如果我不使用 colNames 作为参数,如下所示,程序可以成功运行。我不明白,为什么会出现这种情况。非常感谢。

receivedColModel.push({name:'NAME', index:'NAME', sortable:true, label:messageDictionary['userHistory.NAME']});
receivedColModel.push({name:'SURNAME', index:'SURNAME', sortable:true, label:messageDictionary['userHistory.SURNAME']});
receivedColModel.push({name:'AGE', index:'AGE', sortable:true, label:messageDictionary['userHistory.AGE'});
receivedColModel.push({name:'STATUS', index:'STATUS', sortable:true, label:messageDictionary['userHistory.STATUS']});

if(isUserGlobal == 'true') {
    receivedColModel.push({name:'CITY', index:'CITY', sortable:true});
}

$('#historyGrid').jqGrid({
    url:'ajax.htm',
    datatype: "json",
    mtype: "POST",
    jsonReader: { repeatitems : false, cell:"", id: "", userdata: "jsonModel", root: "rows" },
    postData:postData,
    colModel:receivedColModel,
    .
    .
    .

最佳答案

您没有包含 jqGrid 的真实参数。很明显,您使用 receivedColModelreceivedColNames 来构建 colNames 和 colModel`。我猜你的问题的根源在于这部分(我们在你的问题文本中没有看到的部分)。

您根本不能使用colNames。相反,您可以根据 colModellabel 属性指定列标题。你不会有任何缺点。顺便说一句,如果 index 属性的值与 name 属性的值相同,则不需要该属性。 sortable 属性的默认值为 true,您也可以删除 sortable:true

关于javascript - jqGrid - colNames 和 <> colModel 的长度!错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55222551/

相关文章:

javascript 函数返回未定义

javascript - AngularJS - 根据当前路径更改 href 属性

jquery - Highchart - 线条或区域不从左侧点开始

javascript - 无法弄清楚如何对谷歌应用引擎执行 XMLHttpRequest

javascript - Rails3 中的 Google Instant 式搜索

javascript - Jquery 下拉菜单在远处显示的幻灯片上

javascript - Aurelia,如何进行可选绑定(bind)

javascript - 将 Bootstrap 下拉列表扩展到可见页面的底部

javascript - 查找与指定类最接近的 div

javascript - 这是删除我的页面,Ajax jQuery