所以,我使用的是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的现有代码。事情是,这必须是动态的,以应对未来的增长......
答案 0 :(得分:0)
我觉得自己是一个真正的白痴.....我正在从另一行代码中复制文本,并没有意识到我已经包含了最后一个属性...隐藏:true 所以,当然它并没有出现,因为我告诉它不要显示。猜猜这就是我复制和粘贴代码所能获得的。