当我使用下面的代码时,我收到“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 的真实参数。很明显,您使用 receivedColModel
和 receivedColNames
来构建 colNames
和 colModel`。我猜你的问题的根源在于这部分(我们在你的问题文本中没有看到的部分)。
您根本不能使用colNames
。相反,您可以根据 colModel
的 label
属性指定列标题。你不会有任何缺点。顺便说一句,如果 index
属性的值与 name
属性的值相同,则不需要该属性。 sortable
属性的默认值为 true
,您也可以删除 sortable:true
。
关于javascript - jqGrid - colNames 和 <> colModel 的长度!错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55222551/