grails中添加自定义标签解决gsp页面双层循环问题
Nope,notwiththeeachclause.
I'djustwritemyowntaglibthattakeslist1andlist2anddoestheiterationforyou,yieldingbacktothe
<g:eachCheckedItem list1="${list1}" list2="${list2}">
<input type="checkbox" ... checked="checked"/>
</g:eachCheckedItem>Andinyourtaglibclass:
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
}
}Somethinglikethat(tunedtoyourspecificproblem)iseasytowrite,andalsocleansupyourgspfilequiteabit.Iusethesekindsofcustomiteratorsallthetimeinmytaglibs.
相关推荐
hooopo 2014-07-12
80447518 2014-06-18
purpen 2014-05-23
jackyzhuyuanlu 2015-02-12
龙浩然 2015-11-06
daociyiyou 2016-11-07
coderbx 2013-03-11
yehell 2012-04-24
yeyedeyatou 2011-08-04
Ben的程序员生涯 2011-04-29
jieren 2010-02-18
carpenterworm 2009-04-03
trapeze 2008-06-06
掘井之路 2019-07-01