我正在尝试在 mvc 中实现一个 jquery,有几个关于这个的教程,但我不希望 jquery 对列进行硬编码(或者实际上任何要硬编码的东西 - 这是应该的逻辑在 Controller 中。
所以...查看下面的代码,您将看到 colNames: 和 colModel: 我如何编写这些以便我可以循环遍历模型,为每个列项目向网格添加一列?基本上我最终想要的是一个通用的 jqGrid 语句,唯一改变的是 Controller 中的代码!
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'
});
最佳答案
如果仍然有人在寻找它。
查看博客文章
http://blog.lieberlieber.com/2010/07/07/asp-net-mvc-and-a-generic-jqquery-grid-jqtgrid/
http://blog.lieberlieber.com/2010/07/08/asp-net-mvc-and-a-generic-jqquery-grid-jqtgrid-part-2/
关于model-view-controller - jqgrid如何动态创建列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1684611/