问题描述
- 这个通用操作类相当于JSP页面从struts2里action里找到相应的方法吗
-
//增删改查通用操作类 PageHelper = { Entity: function () { }, getInstance: function () { return new this.Entity(); } }; PageHelper.Entity.prototype = { ContentContainer: null, CheckBoxAll: null, FlipParams: { "conditions": null, "pageIndex": null, "pageSize": null, "multipleIds": null }, Model: null, PagerCanvas: "#Pager", Url: { add: null, load: null, modify: null, remove: null, template: null }, //method add: function (callback) { $.ajaxPostJson(this.Url.add, this.Model, callback); }, ajax: function (url, param, callback) { $.ajaxPostJson(url, param, callback); }, //翻页 flip: function (i, initPagerFlag) { var _t = this; if (typeof this.FlipParams == "undefined" && this.point) _t = this.point; //Ajax请求参数 _t.FlipParams.conditions = _t.Model; _t.FlipParams.pageIndex = i || parseInt($("#pageIndex").val()); _t.FlipParams.pageSize = parseInt($("#pageSize").val() || "10"); _t.FlipParams.multipleIds = $("#multipleIds").val(); //发送AJAX请求分页数据并填充 $.ajaxPostJson(_t.Url.load, _t.FlipParams, function (jsn) { if (jsn.status) { $(_t.ContentContainer).html(""); if (jsn.resultHtml) { $(_t.ContentContainer).html(jsn.resultHtml); } else if (jsn.list) { $(_t.ContentContainer).empty().setTemplateURL(_t.Url.template); $(_t.ContentContainer).processTemplate(jsn.list); //OC审计报告汇总 Modify by yhl 2014/3/25 start var checkedLength = $(_t.ContentContainer+" input[type=checkbox][checked]").length; if (checkedLength >0 && checkedLength == _t.FlipParams.pageSize) { $(_t.CheckBoxAll).attr("checked",true); } else { $(_t.CheckBoxAll).removeAttr("checked"); } //OC审计报告汇总 Modify by yhl 2014/3/25 end setTimeout(function () { showButtons() }, 0); //Modify By zhexin.zou 2013/8/7 start setTimeout(function () { bindSelectFunc('staffList'); }, 500); //Modify By zhexin.zou 2013/8/7 end } if (initPagerFlag) { $(_t.PagerCanvas).html(""); $("#pageIndex").val("1"); $("#pageCount").val(jsn.pageCount); _t.pagerInit(); }; } else { if (jsn.message) alert(jsn.message); } }); }, //修改记录 modify: function () { $.ajaxPostJson(this.Url.modify, this.Model, void (null)); }, query: function () { this.flip(1, true); }, //删除记录 remove: function (callBack) { $.ajaxPostJson(this.Url.remove, this.Model, function (jsn) { if (jsn) { if (jsn.status) { if (callBack) callBack(jsn); else { alert(jsn.message); } } else { alert(jsn.message); } } }); }, //初始化 pagerInit: function (t) { t = t || this; var pagerParam = { canvas: t.PagerCanvas, callbackFn: t.flip, pageCount: parseInt($("#pageCount").val()), pageIndex: parseInt($("#pageIndex").val()), point: t }; var pg = Pager.getInstance(); pg.init(pagerParam); } }; //填充模型 var fillModel = function (model, index) { var val; for (var m in model) { //val = $.trim($("#" + m + index.toString()).val()) || null; var el = $("#" + m + index.toString()); if (el.attr("type") == "checkbox") { val = el.is(":checked"); } else val = $.trim(el.val()) || null; model[m] = val; }; model.id = $("#editID").val() || 0; return model; }; $("#inptAddNew").on("click", function () { $(".readOnlyOnEdit").removeAttr("readonly"); });
下面的代码调用上面的通用操作类
$(function () {
var url = {load: contextPath + "/ouQuery/searchReport",
remove: contextPath+"/ouQuery/delet",
template: contextPath + "/resources/templates/pricelzx/OuQuery.tpl",
add: contextPath + "/ouQuery/edit"
};
var ph = PageHelper.getInstance();
var lb = new lightBox();
ph.Url = url;
ph.ContentContainer = "#tbList tbody";
ph.pagerInit();
// query
$("#inptQuery").on("click", function () {
//查询时执行验证
if (!new Validate().execute("tbQuery")) {
return false;
}var ouQueryModel = Model.OuQuery; ph.Model = fillModel(ouQueryModel,1); ph.query(); }); 第二个代码 //delete删除 $("table input.del").live("click", function () { if (confirm(regional.operate.deleteConfirm)) { var ouQueryModel = Model.OuQuery; ouQueryModel.id = $(this).parent().siblings().first().attr("data"); ph.Model = ouQueryModel; ph.remove(null); //reset params ph.Model = fillModel(ouQueryModel, 1); ph.query(); lb.hide(); } }); ph.remove(null);为什么括号里是null
解决方案
这是js的代码,ajax获取数据,crud的。
时间: 2024-09-16 02:51:57