1.點(diǎn)擊列表中的“發(fā)送消息”须尚,只有第一行響應(yīng)振愿,其它后面的list無效
頁(yè)面截圖
因?yàn)閕d選擇器表示唯一。第一行有id红选,后面的就不會(huì)有同樣的id了澜公。不能循環(huán)設(shè)置id,所以此處需要將id選擇器換成類選擇器
//錯(cuò)誤代碼 id選擇器"#"
<span userId="${data.userId}"
class="btn btn-xs btn- btn-info" data-toggle="model"
data-target="#myModal" id="sysStaffMsg">發(fā)送消息</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">發(fā)送消息</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代碼中獲取不到
頁(yè)面截圖2
此處使用 $("#sendSysMsgForm").find("input[name=userId]") 強(qiáng)烈定位該輸入框
<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.無返回值時(shí)
//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="雇員資金明細(xì)">資金明細(xì)</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>序號(hào)</th>
<th>訂單號(hào)</th>
<th>時(shí)間</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>對(duì)不起喇肋,沒有查詢到記錄!</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">收入總計(jì):</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">發(fā)送</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("發(fā)送成功!");
$('#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>() {
});
}