gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 23:59:53 24 4
gpt4 key购买 nike

当我使用下面的代码时,我收到“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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com