加载< c:forEach>的内容懒洋洋 [英] loading contents of <c:forEach> lazily

查看:69
本文介绍了加载< c:forEach>的内容懒洋洋的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在< div> 中实现实时滚动或延迟滚动,其中< forEach> 循环。我在< div> 中有以下代码,我想懒洋洋地加载内容。

Is it possible to implement live scrolling or lazy scrolling in a <div> which has <forEach> loop. I have the following codes in a <div>, I want to load the contents lazily.

<div class="update" id="update">

                    <c:forEach var="p" items="#{statusBean.statusList}"
                        varStatus="loop">
                        <h:form>
                            <c:if test="${p.statusmsg!=null}">
                                <div class="status">
                                                                //content
                                </div>
                            </c:if>
                        </h:form>
                    </c:forEach>
</div>


推荐答案

JSTL和EL都只能在视图构建期间使用页面的时间(由服务器完成)。 Ajax请求不属于视图构建时间,因为它们位于客户端浏览器中,因此JSTL和EL无法处理ajax请求。不过,你可以使用如下所述的普通servlet使用ajax:如何使用Servlet和Ajax?

Both JSTL and EL will be able only during view build time of the page (this is done by server). Ajax requests aren't part of view build time since they're in client browser, so JSTL and EL are useless to handle ajax requests. Still, you can make use of ajax with plain servlets as stated here: How to use Servlets and Ajax?

因为您在代码中使用了JSF(基于使用延迟评估表达式,如#{statusBean.statusList} < h:form> )并假设你使用JSF 2+,在 OmniFaces 展示: < o:componentIdParam> 可展开列表示例显示您可以对 @RequestScoped 托管bean进行ajax调用并检索一个JSON 字符串并使用它来更新客户端的值,如HTML dom。

Since you're using JSF in your code (based on the use of deferred evaluation expression like #{statusBean.statusList} and <h:form>) and assuming you use JSF 2+, there's a good example in OmniFaces showcase: <o:componentIdParam>, the Expandable list example shows that you can make an ajax call to a @RequestScoped managed bean and retrieve a JSON String and use it to update values on client side like HTML dom.

基于<的实时滚动示例a href =https://stackoverflow.com/a/8123681/1065197>这个答案:

$(window).scroll(function(){
    if  ($(window).scrollTop() == $(document).height() - $(window).height()){
       loadNewData();
    }
});

function loadNewData(){
    /* add code to fetch new content and add it to the DOM */
}

这篇关于加载&lt; c:forEach&gt;的内容懒洋洋的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆