1、edit.jsp
$("input[name='fdKpsqNumberId']").change(function () {
var fdKpsqNumberId = $("input[name='fdKpsqNumberId']").val();
$.ajax({
data: {fdKpsqNumberId: fdKpsqNumberId},
url: "${LUI_ContextPath}/contract/manage/contract_manage_tpsq/contractManageTpsq.do?method=queryKpsqListSjmx",
dataType: 'json',
success: function (data) {
RemoveDocListTr('TABLE_DocList_fdSjmx_Form');
for (var i = 0; i < data.length; i++) {
var arraySon = data[i];
var fieldValues = {};
fieldValues['fdSjmx_Form[!{index}].fdSjlx'] = arraySon['fdSjlx'];
fieldValues['fdSjmx_Form[!{index}].fdJe'] = arraySon['fdJe'];
fieldValues['fdSjmx_Form[!{index}].fdRemark'] = arraySon['fdRemark'];
DocList_AddRow("TABLE_DocList_fdSjmx_Form", null, fieldValues)
}
}
}
)
window.RemoveDocListTr = function (tableId) {
var $trs = $('#' + tableId + ' tr');
for (var i = 1; i < $trs.length; i++) {
DocList_DeleteRow($trs[i]);
}
}
})
当某个元素变动就会请求 url(对应的后端的方法) 并把从url 得到的 json 数据写到明细表
2、Action
public ActionForm queryKpsqListSjmx(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
String fdKpsqNumberId = request.getParameter("fdKpsqNumberId");
if (StringUtil.isNotNull(fdKpsqNumberId)) {
ContractManageKpsq contractManageKpsq = (ContractManageKpsq) getContractManageKpsqService().findByPrimaryKey(fdKpsqNumberId);
List<ContractManageSjmx> fdSjmx = contractManageKpsq.getFdSjmx();
JSONArray objects = new JSONArray();
if (null != fdSjmx && fdSjmx.size() > 0) {
for (ContractManageSjmx sjmx : fdSjmx) {
JSONObject jsonObject = new JSONObject();
jsonObject.put("fdSjlx", sjmx.getFdSjlx());
jsonObject.put("fdJe", sjmx.getFdJe());
jsonObject.put("fdRemark", sjmx.getFdRemark());
objects.add(jsonObject);
}
}
response.setCharacterEncoding("UTF-8");
response.getWriter().write(objects.toString());
}
return null;
}
通过传过来的 id 查出来对应的数据并把他写出去