欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

后端返回集合给前端,前端div接受循环显示

程序员文章站 2022-05-28 22:07:32
...

前端代码:

 <div class="article-foot"></div>
 
 function  findContent(dId) {
        $.ajax({
            type: "GET",
            url: "dangerinformaticas/getContent?dangerId=" + dId,
            dataType: "json",
            success: function (data) {

                if (data.length == 0) {
                //如果查出来的数据为空,则div隐藏
                    $(".article-foot").hide();
                } else {
                    $(".article-foot").show();
                    for (var i = 0; i < data.length; i++) {
                    //评论查出来的是列表
                        var userName = data[i].userName;
                        var content = data[i].content;
                        data[i].createTime=data[i].createTime.substring(0,10);
                        var createTime = data[i].createTime;
                        var imgePath = data[i].imgePath;
                        var div= "<div class=\"clearfix comment-cnt\" >\n" +
                            "  <a class=\"pull-left thumb-small m-r-small\">\n" +
                            "  <span class=\"btn btn-circle btn-white btn-mini\"><img src=\"employees/showImages?imgePath="+ imgePath+"\" class=\"img-circle\" id=\"imgUrlHead\"></span>\n" +
                            " </a>\n" +
                            " <span>" + userName + "</span><b>:</b>\n" +
                            " <span>" + content + "</span>\n" +
                            " <span class=\"text-muted m-l-small pull-right\">" + createTime + "<i class=\"icon-time\"></i></span>\n" +
                            " </div>";
                       var divs=divs+div;
                    }
                    $(".article-foot").html(divs);
                }
            }
        });
    }

后端接口方法

  @GetMapping("/getContent")
    @ApiOperation(value = "列表")
    public List<Conment> list(String dangerId) {
        return conmentDao.getByDangerId(dangerId);
    }

后端返回集合给前端,前端div接受循环显示效果展示:评论全部展示!

相关标签: 前端显示