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


    

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.

你可能感兴趣的:(grails)