You need to parse the json into a list of maps:
This should work for grails 1.3.7
<g:each var="question" in="${grails.converters.JSON.parse( confHolder.config.faq )}">
Вопрос
I have the following code:
<g:each var="question" in="${confHolder.config.faq}">
<h1>${question.question}</h1>
<h1>${question.answer}</h1>
</g:each>
In my conf file I have the following json:
faq = [{"question":"What is this", "answer":"This thing"}, {"question":"What is this", "answer":"This thing"}];
I know that I'm reading in the file correctly because I can do:
<script type="text/javascript">
var faq = ${confHolder.config.faq}
for(var ii=0; ii<faq.length; ii++)
alert(faq[0].question);
</script>
And it will alert out my question.
How can I loop through my json in the each
tag and print out the questions and answers in the <h1></h1>
tag?
Решение
You need to parse the json into a list of maps:
This should work for grails 1.3.7
<g:each var="question" in="${grails.converters.JSON.parse( confHolder.config.faq )}">