0
所以,我使用jqGrid,由于这个项目的性质,我需要动态地构建出colModel。意思是,我需要动态地建立模型本身。我正在用我的JSON调用检索数据。 因此,我建立一个对象数组,然后将该数组分配给colModel属性。没有错误,但数据不显示....我正在做一些非常类似于colNames的东西,它工作正常。有人看到我失踪了吗?我昨天下午和今天早上一直在做这件事,并且找不到任何不应该起作用的理由。正如你所看到的,它将我的代码顶部的siteVal数组赋给colModel属性。jqGrid中动态构建的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的现有代码。事情是,这必须是动态的,以应对未来的增长......
您在浏览器的控制台中是否收到错误消息? –
根本没有。这是什么让我如此困惑..它似乎会显示一个错误,如果它不加载.. – trouble706
首先你应该总是写jqGrid的哪个分支([免费jqGrid](https://github.com)/free-jqgrid/jqGrid),[Guriddo jqGrid JS](http://guriddo.net/?page_id=103334)或版本<= 4.7中的旧jqGrid)以及您在测试中使用的版本。秒使用'siteId'生成'colModel',但不包含任何您使用的数据。 'name'属性必须包含id规则(例如没有空格)。在'colModel'中设置'index'不是必需的,不推荐使用,缺省值为editable:false,sortable:false,align:'left''的属性也可以跳过。 – Oleg