Resulting JSON that is produced:
ResultSet {['text':'google', 'url':'http://www.google.com'], ...}
def writer = new StringWriter();
new grails.util.JSonBuilder(writer).json {
ResultSet {
links.each { link ->
Links(text: link.text, url: link.url)
}
}
}
writer.toString()
This is the code to do the same with HTML, you would use the Groovy XML MarkupBuilder instead.
Resulting HTML that is produced:
StringWriter w = new StringWriter()
def builder = new groovy.xml.MarkupBuilder(w)
builder.div (class: 'className'){
links.each { link ->
p {
b 'Title: '
builder.yield link.text
}
}
}
w.toString()
<div class="className">
<p><b>Title: </b>google</p>
</div>
No comments:
Post a Comment