首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网络技术 > 网络基础 >

grails中添加自定义标签解决gsp页面双层循环有关问题

2013-11-25 
grails中添加自定义标签解决gsp页面双层循环问题Nope, not with the each clause.Id just write my own t

grails中添加自定义标签解决gsp页面双层循环问题
Nope, not with the each clause.

I'd just write my own taglib that takes list1 and list2 and does the iteration for you, yielding back to the

<g:eachCheckedItem list1="${list1}" list2="${list2}">    <input type="checkbox" ... checked="checked"/></g:eachCheckedItem>

And in your taglib class:

def eachCheckedItem = { attrs, body ->    def list1 = attrs.list1    def list2 = attrs.list2    list1.findAll { list2.contains(it) }.each {        out << body(listItem: it)  // access to listItem variable inside gsp    }}

Something like that (tuned to your specific problem) is easy to write, and also cleans up your gsp file quite a bit. I use these kinds of custom iterators all the time in my taglibs.

热点排行