Groovy 标记生成器标签
有没有办法修改之前答案中的代码
import groovy.xml.MarkupBuilder
def writer = new StringWriter()
def builder = new MarkupBuilder(writer)
def awaiting = ['one', 'two', 'three']
builder.html {
ul {
awaiting.each {
li(it.toString())
}
}
}
println writer.toString()
,以便添加标签而不是发送它 - 例如
builder.html{
tag{
awaiting.each{}
}
} return result
可以是“ol”或“ul”
Is there a way to modify the code from a previous answer
import groovy.xml.MarkupBuilder
def writer = new StringWriter()
def builder = new MarkupBuilder(writer)
def awaiting = ['one', 'two', 'three']
builder.html {
ul {
awaiting.each {
li(it.toString())
}
}
}
println writer.toString()
so that if you add a tag instead that you send it - like
builder.html{
tag{
awaiting.each{}
}
} return result
could be 'ol' or 'ul' for example
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以依赖 GString,并且可以通过其字符串值调用函数。
You can rely on the GStrings and the fact that you can call a function by its string value.
您还可以使用 invokeMethod,它比上面的更明确,尽管有点长。
You could also use invokeMethod which is more explicit then the above, albeit a little bit longer.