1.点击列表中的“发送消息”,只有第一行响应,其它后面的list无效
因为id选择器表示唯一。第一行有id,后面的就不会有同样的id了。不能循环设置id,所以此处需要将id选择器换成类选择器
//错误代码 id选择器"#"
<span userId="${data.userId}"
class="btn btn-xs btn- btn-info" data-toggle="model"
data-target="#myModal" id="sysStaffMsg">发送消息</span>
$("#sysStaffMsg").click(function () {
var userId = $(this).attr("userId");
var data = {
userId: userId
}
var url = Main.contextPath + "/staff/popupStaff/"+userId;
$.popup.modal(url,data)
});
//正确代码 类选择器"."
<span userId="${data.userId}"
class="btn btn-xs btn- btn-info sysStaffMsg" data-toggle="model"
data-target="#myModal">发送消息</span>
$(".sysStaffMsg").click(function () {
var userId = $(this).attr("userId");
var data = {
userId: userId
}
var url = Main.contextPath + "/staff/popupStaff/"+userId;
$.popup.modal(url,data)
});
//java
@Controller
@RequestMapping("staff")
public class StaffController {
@RequestMapping(value = "popupStaff/{userId}")
public String popupStaff(Model model, @PathVariable("userId") String userId) {
StaffCenterResult rs = restClientFactory.newRestClient().post(UrlUntils.getUrl(ConfigConst.STAFF_DETAIL),userId,new TypeReference<StaffCenterResult>() {
});
model.addAttribute("data", rs);
return "main/staffMsgAdd";
}
}
2.雇员和雇员id 在js代码中获取不到
此处使用 $("#sendSysMsgForm").find("input[name=userId]") 强烈定位该输入框
<div class="input-group">
<span class="input-group-addon">雇员ID</span>
<input type="text" id="name" name="userId"
class="form-control"value="${data.userId}"
validate="{required:true}"/>
</div>
//无法获取userId值
var userId= $("#name").val();
//正确获取userId值
var userId = $("#sendSysMsgForm").find("input[name=userId]").val();
3.无返回值时
//jsp
<span userId="${data.userId}"
data-addtab="auth_edit1"
url="${ctx}/staff/cash/${data.userId}/1"
class="btn btn-xs btn- btn-info detail" title="雇员资金明细">资金明细</span>
//java
@RequestMapping("/cash/{userId}/{type}")
public String searchUserAuth(Model model, CashSearchParam cashSearchParam, @PathVariable("userId") String userId,@PathVariable("type") String type) {
CashSearchResult rs = restClientFactory.newRestClient().post(UrlUntils.getUrl(ConfigConst.CASH), cashSearchParam, new TypeReference<CashSearchResult>() {
});
model.addAttribute("cashSearchParam", cashSearchParam);
model.addAttribute("total",rs.getTotal());
model.addAttribute("data", rs.getData().getData());
model.addAttribute("startPos", cashSearchParam.getPagination().getStartPos());
model.addAttribute("pageCount", rs.getData().getTotal());
return "main/cash";
}
//cash.js
<html>
<head>
<title>Title</title>
</head>
<body>
<form:form action="${ctx}/staff/cash/${cashSearchParam.userId}/${cashSearchParam.type}" id="cashForm" method="post"
commandName="cashSearchParam">
<div class="exist-wrap">
<div class="row">
<div class="col-md-3">
<div class="input-group">
<%--<span class="input-group-addon">xx</span>--%>
<%--<form:input type="text" class="form-control" path="interfaceUrl"/>--%>
<form:input type="hidden" path="userId" id="restAuthUserId" value="${cashSearchParam.userId}"/>
<form:input type="hidden" path="type" id="restAuthUserId" value="${cashSearchParam.type}"/>
</div>
</div>
<%--<div class="col-md-2 searchBtnContinue">--%>
<%--<span class="search-btn" id="cashSearch">搜索</span>--%>
<%--</div>--%>
</div>
</div>
<page:paging pageCount="${pageCount}" page="${startPos}">
<table id="userSearchTable" class="htable">
<colgroup>
<col width="3%"/>
<col width="18%"/>
<col width="15%"/>
<col width="15%"/>
<col width="15%"/>
<col width="14%"/>
</colgroup>
<thead>
<tr>
<th>序号</th>
<th>订单号</th>
<th>时间</th>
<th>金额</th>
<th>描述</th>
<th>剩余可用资金</th>
</thead>
<tbody>
<c:if test="${pageCount==0}">
<tr>
<td colspan="6" class="tablenothing">
<span><i class="icon icon-frown icon-3x"></i><span>对不起,没有查询到记录!</span></span>
</td>
</tr>
</c:if>
<c:if test="${pageCount!=0}">
<c:forEach var="data" items="${data}" varStatus="status">
<tr>
<td class="sno">${(status.index + 1)+(startPos-1)*10}</td>
<td class="text" id="orderId">${data.orderId}</td>
<td class="text" id="date"><fmt:formatDate value="${data.date}"
pattern="yyyy-MM-dd HH:mm:ss"/></td>
<c:choose>
<c:when test="${data.type ==1 || data.type ==3 || data.type ==5}">
<td class="text" id="cashAmount">+${data.cashTotal}</td>
</c:when>
<c:when test="${data.type ==2 || data.type ==4 || data.type ==6}">
<td class="text" id="cashAmount">-${data.cashTotal}</td>
</c:when>
<c:otherwise>
<td class="text" id="cashAmount">${data.cashTotal}</td>
</c:otherwise>
</c:choose>
<%--<td class="text" id="userId" style="display: none">${data.userId}</td>--%>
<td class="text" id="descri">${data.descri}</td>
<td class="text" id="cashAmount">${data.cashAmount}</td>
</tr>
</c:forEach>
</c:if>
</tbody>
</table>
</page:paging>
<c:if test="${cashSearchParam.type =='1'}">
<span class="text" id="xx" style="color: red">收入总计:</span>
<td class="text" id="aa">${total}</td>
</c:if>
</form:form>
</body>
</html>
<%--<script type="text/javascript" src="<c:url value='/static/js/rest/authList.js'/>"></script>--%>
4.有返回值
//jsp
<button type="button" id="sysStaffSend" class="btn btn-primary">发送</button>
//js
$("#sysStaffSend").click(function () {
var url = Main.contextPath + "/staff/sendstaffmsg" ;
var sysMsgContent = $("#sysMsgContent").val();
var userId = $("#sendSysMsgForm").find("input[name=userId]").val();
var name = $("#sendSysMsgForm").find("input[name=name]").val();
console.log(sysMsgContent);
var data = {
sysMsgContent: sysMsgContent,
userId:userId
}
if ($.valid.validCommon($("#sendSysMsgForm"))) {
$.ajaxCommon.postUrl(url, data, function (result) {
if (result) {
$.alertMessage.info("发送成功!");
$('#myModal').modal('hide');
}
})
}
});
//java
@RequestMapping("/sendstaffmsg")
public
@ResponseBody
boolean sendStaffMsg(Model model, SendStaffMessageInfo sendStaffMessageInfo) {
return restClientFactory.newRestClient().post(UrlUntils.getUrl(ConfigConst.STAFF_MESSAGE_SEND), sendStaffMessageInfo, new TypeReference<Boolean>() {
});
}