Java js小结1

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代码中获取不到

页面截图2

此处使用 $("#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>() {
        });
    }
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 135,768评论 19 139
  • 1. Java基础部分 基础部分的顺序:基本语法,类相关的语法,内部类的语法,继承相关的语法,异常的语法,线程的语...
    子非鱼_t_阅读 32,083评论 18 399
  • 从三月份找实习到现在,面了一些公司,挂了不少,但最终还是拿到小米、百度、阿里、京东、新浪、CVTE、乐视家的研发岗...
    时芥蓝阅读 42,473评论 11 349
  • 吾日三省吾身: 白乎? 富乎? 美乎? 皆否! 知此道者, 必勤学焉。 学习学的累了想休息, 打开支付宝看看余额,...
    叶轻筠阅读 910评论 0 0
  • 前端遮罩组件 pc/|-- index.html 内含css,js|-- img 存放...
    beforerFE阅读 3,931评论 0 0