开发者

Problem with Grails g:each tag

开发者 https://www.devze.com 2023-03-17 04:30 出处:网络
I\'m struggling to get a g:each tag to work. What I\'m passing to the view is a list of hashmaps (something like this [ [ : ] , [ : ] ]).

I'm struggling to get a g:each tag to work. 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]. The code is the following:

CONTROLLER in the controller I'm passing the following:

[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. 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

<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>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号