简体   繁体   English

Grails g:each 标签的问题

[英]Problem with Grails g:each tag

I'm struggling to get ag:each tag to work.我正在努力让 ag:each 标签工作。 What I'm passing to the view is a list of hashmaps (something like this [ [: ], [: ] ] ).我传递给视图的是哈希图列表(类似于 [ [: ], [: ] ] )。 Each hashmap is of the form [location: somelocation, artist: someartist].每个 hashmap 的格式为 [location: somelocation, artist: someartist]。 The code is the following:代码如下:

CONTROLLER in the controller I'm passing the following: controller中的 CONTROLLER 我正在传递以下内容:

[searchedResults : results.searchedResults]

VIEW看法

<g:each status="i" in="${searchedResults}" var="results">
   if(results.location!=null){
       var point${results.location.id} = new google.maps.LatLng(${results.location.lat}, ${results.location.lng});
       var myMarkerOptions${results.location.id} = {
                          position: point${results.location.id}, 
                          map: map
                         };
       var marker${results.location.id} = new google.maps.Marker(myMarkerOptions${results.location.id});   
   }    
</g:each>

Any ideas why this wouldn't work?任何想法为什么这不起作用? Thanks!谢谢!

GrailsGuy is right in that you can't write groovy code in the body of an each tag like that. GrailsGuy 是正确的,因为您不能在每个标签的正文中编写 groovy 代码。 But let me try and convert it to something for you, since it looks like your doing some javascript in there as well...I think all you need to fix is your if statement但是让我尝试将其转换为适合您的东西,因为看起来您在那里也做了一些 javascript ......我认为您需要修复的只是您的 if 语句

<g:each status="i" in="${searchedResults}" var="results">
  <g:if test="${results.location}">
    //everything else seems like it would work, assuming your javascript
    // code is accurate
  </g:if>
</g:each>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM