【发布时间】:2009-11-06 00:24:59
【问题描述】:
我正在尝试在 mvc 中实现一个 jquery,对此有几个教程,但我不希望 jquery 对列进行硬编码(或者实际上任何要硬编码的东西 - 这是逻辑应该在控制器中。
所以...查看下面的代码,您会看到 colNames: 和 colModel: 我如何编写这些以便循环遍历模型,为每个列项在网格中添加一列?基本上我最终想要的是一个通用的 jqGrid 语句,唯一改变的是控制器中的代码!
Query("#list").jqGrid({
url: '/Home/GetMovieData/',
datatype: 'json',
mtype: 'GET',
colNames: ['id', 'Movie Name', 'Directed By', 'Release Date', 'IMDB Rating', 'Plot', 'ImageURL'],
colModel: [
**{ name: 'id', index: 'Id', width: 55, sortable: false, hidden: true },
{ name: 'Movie Name', index: 'Name', width: 250 },
{ name: 'Directed By', index: 'Director', width: 250, align: 'right' },
{ name: 'Release Date', index: 'ReleaseDate', width: 100, align: 'right' },
{ name: 'IMDB Rating', index: 'IMDBUserRating', width: 100, align: 'right' },
{ name: 'Plot', index: 'Plot', width: 55, hidden: true },
{ name: 'ImageURL', index: 'ImageURL', width: 55, hidden: true}],**
pager: jQuery('#pager'),
rowNum: 5,
rowList: [5, 10, 20],
sortname: 'id',
sortorder: "desc",
height: '100%',
width: '100%',
viewrecords: true,
imgpath: '/Content/jqGridCss/redmond/images',
caption: 'Movies from 2008'
});
【问题讨论】:
标签: model-view-controller jqgrid