我想显示来自数据库的数据使用ajax,jQuery移动和spring mvc。
示例:在表格中显示课程名称列表。
我现在使用jqgrid来显示数据,但是有没有其他不使用数据的替代方法呢?论坛中有很多人,但大多数人使用php,而我使用的是spring mvc控制器。
请大家帮帮我..
发布于 2012-05-14 15:50:08
不确定jqgrid是否适用于jquery mobile,但对于一个普通的web应用程序,您可以使用addJSONData方法,并将jsonReader和datatype属性设置为一个函数。下面是一个示例:
function cfgWixGenApplicationsGrid() {
var cond = null;
$("#tblWixGenApplications").jqGrid({
datatype: function (postdata) {
var orderByExpr = "";
if (postdata.sidx != "") {
orderByExpr = postdata.sidx + " " + postdata.sord;
}
getPageList(cond, postdata.page, postdata.rows, orderByExpr, hSuccPageWixGenApplications, hError);
},
colNames: ["Id", "Title", "Name", "Version", "MainAssemblyName"
],
colModel: [
{ name: "Id", index: "Id", width: 50, sorttype: "String", editable: false },
{ name: "Title", index: "Title", width: 50, sorttype: "String", editable: true },
{ name: "Name", index: "Name", width: 50, sorttype: "String", editable: true },
{name: "Version", index: "Version", width: 50, sorttype: "String", editable: true },
{name: "MainAssemblyName", index: "MainAssemblyName", width: 50, sorttype: "String", editable: true }
],
multiselect: false,
pager: "#divPagerWixGenApplications",
viewrecords: true,
jsonReader: { repeatitems: false, root: "rows", page: "page", records: "records", total: "total" },
rowNum: 10,
rowList: [10, 20, 30]
});
}getPageList执行ajax调用,在我的示例中是对WCF服务的调用。我想你可以在这里调用MVC url。
hSuccPageWixGenApplications函数调用addJSONData的方式如下:
function hSuccPageWixGenApplications(pageData) {
var list = [];
$.each(pageData.List, function (index, value) {
if (!value.IsDeleted) {
list.push(value);
}
});
var grid = $("#tblWixGenApplications")[0];
var pData = new Object();
var recCount = pageData.RecordCount == null ? 1000 : pageData.RecordCount;
pData.page = pageData.PageNo;
pData.records = recCount;
pData.rows = list;
pData.total = recCount / pageData.PageSize;
grid.addJSONData(pData);
};https://stackoverflow.com/questions/10578867
复制相似问题