簡體   English   中英

ui:在JavaScript中重復

[英]ui:repeat inside a javascript

有什么辦法可以在javascript中執行ui:repeat? 這就是我想要做的。

var point;
<ui:repeat value="#{testController.allItems}" var="item">
  point = new google.maps.LatLng(item.latitude,item.longitude);
  createMarker(point, item.name, item.desc);   
</ui:repeat>

testController.allItems返回具有經度和緯度及其他值的實體的列表,我正在嘗試使用Google Maps進行商店定位。 createMarker將標記添加到地圖。

還是有更好的方法來做到這一點?

您可以嘗試(另一個選項: c:forEach ):

        <script type="text/javascript">
                var point;
                <ui:repeat value="#{s9.list}" var="item">
                   point = new google.maps.LatLng(#{item.latitude},#{item.longitude});
                   createMarker(point, #{item.name}, #{item.desc});
                </ui:repeat>
        </script>

如果您的函數需要String參數,則應使用'',例如:

    google.maps.LatLng('#{item.latitude}','#{item.longitude}');
    createMarker(point, '#{item.name}', '#{item.desc}');

我遇到了這個問題(c:forEach也不起作用)。 使用<h:outputScript>標記而不是<script>標記可以解決此問題。 使用<h:outputScript>標記,我可以使用ui:repeat

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM