ui:repeat inside a javascript

只愿长相守 提交于 2019-12-12 22:11:04

问题


is there any way to perform a ui:repeat inside a javascript? this is what i'm trying to do.

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 returns a list of entities with latitude and longitude and other values, i'm trying to do a store locator using google maps. createMarker adds marker to the map.

or is there a better way to do this?


回答1:


You can try(another option: 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>

If your function require String parameter, you should use '', for ex:

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



回答2:


I had this issue (c:forEach would not work either). Using the <h:outputScript> tag instead of the <script> tag resolved the problem. With the <h:outputScript> tag I could use ui:repeat



来源:https://stackoverflow.com/questions/16410221/uirepeat-inside-a-javascript

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!