我在jqGrid中动态构建的colModel有什么问题?

What's wrong with my dynamically built colModel in jqGrid?

本文关键字:什么 问题 colModel jqGrid 动态 构建 我在      更新时间:2023-09-26

所以,我使用jqGrid,由于这个项目的性质,我需要动态地构建colModel。也就是说,我需要动态地构建模型本身。我正在检索数据与我的JSON调用。我建立了一个对象数组然后把那个数组赋值给colModel属性。没有错误,但是数据没有显示....我正在做一些与colNames非常相似的事情,它工作得很好。有人知道我错过了什么吗?我昨天下午和今天整个上午都在做这个,找不到任何不工作的理由。正如你所看到的,它将我的代码顶部的siteVal数组赋值给colModel属性。

var siteVal = [{name: 'InvtId', index: 'InvtId', width:   20, editable: false, sortable: false, align: 'left', hidden: true}];
siteVal.push({name: 'Descr', index: 'Descr', width: 320, sortable: false, editable: false, align: 'left'});
siteId.forEach(function(site){
    curSite = site.substr(0,1)+"Val";
    siteVal.push({name: curSite, index:curSite, width: 20, editable: false, sortable: false, align: 'left', hidden: true});
})
siteVal.push({name: 'Qty', index: 'Qty', width: 100, editable: true, sortable: false, align: 'right', hidden: true});
    var colData = ['', 'Description'];
colData = colData.concat(siteId);
colData = colData.concat('Quantity');
console.log(colData);
jQuery("#list3").jqGrid({
    url: 'OrdersInput.php?do=getdelvprice&state=' + $("#State").val() + '&city=' + $("#City").val() + '&FType=' + $("#FType").val() + '&siteid=' + $("#Plant").val(),
    datatype: 'json',
    mtype: 'GET',
    colNames: colData,
    colModel:  siteVal,
    loadonce: true,
    height: 525,
    width: 605,
    rowNum: 1000,
    key: false,
    cellEdit: true,
    cellsubmit: 'clientArray',
    gridComplete: function() {
        $("#MsgDel2").html("");
    }
});

在使用console.log查看构建后的数组时,我得到的结果如下:

    {"name":"InvtId","index":"InvtId","width":20,"editable":false,"sortable":false,"align":"left","hidden":true},
{"name":"Descr","index":"Descr","width":320,"sortable":false,"editable":false,"align":"left"},
{"name":"TVal","index":"TVal","width":20,"editable":false,"sortable":false,"align":"left","hidden":true},
{"name":"MVal","index":"MVal","width":20,"editable":false,"sortable":false,"align":"left","hidden":true},
{"name":"PVal","index":"PVal","width":20,"editable":false,"sortable":false,"align":"left","hidden":true},
{"name":"DVal","index":"DVal","width":20,"editable":false,"sortable":false,"align":"left","hidden":true},
{"name":"WVal","index":"WVal","width":20,"editable":false,"sortable":false,"align":"left","hidden":true},
{"name":"BVal","index":"BVal","width":20,"editable":false,"sortable":false,"align":"left","hidden":true},
{"name":"Qty","index":"Qty","width":100,"editable":true,"sortable":false,"align":"right","hidden":true}

这看起来就像我认为它应该看,它完全模仿现有的代码,其中colModel是静态定义的。重要的是,这必须是动态的,以考虑到未来的增长…

我觉得自己真是个白痴.....我正在从另一行代码复制文本,没有意识到我已经包含了最后一个属性……隐藏:真所以,它当然没有出现,因为我告诉它不要出现。我猜这就是我复制粘贴代码的结果