簡體   English   中英

jqGrid-colNames和<> colModel的長度! 錯誤

[英]jqGrid - Length of colNames and <> colModel! error

當我在下面使用此代碼時,我會收到“ colNames和<> 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屬性的值相同,則不需要index屬性。 sortable屬性的默認值為true ,您也可以刪除sortable:true

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM