문제
내 앱에 두 개의 도메인이 선언되어 있습니다.
class Posts {
String title
String content
static hasMany = [tags:Tag]
static constraints = {
}
}
class Tag {
String Name
static belongsTo = Post
static hasMany = [posts:Post]
static constraints = {
}
String toString()
{
"Tag:${Name}"
}
}
결과의 검색 및 표시를 관리하는 컨트롤러가 있습니다.
package com.trafigura.com.trafigura
class ViewerController {
def defaultAction='search'
def search={}
def show = {
def _foundPost = Post.findAllBytitle(params.title)
return [posts: _foundPost, term: params.title]
}
}
search.gsp 코드는 다음과 같습니다.
<html>
<head><title>Simple GSP page</title></head>
<body>Place your content here.
<formset>
<legend>TagsPosts</legend>
<g:form action="show">
<label for="title">Title</label>
<g:textField name="title" />
<g:submitButton name="search" value="Search"/>
</g:form>
</formset>
</body>
</html>
Show.gsp의 다음 코드.
<html>
<head><title>Simple GSP page</title></head>
<body><h1>Results</h1>
for items matching <em>${term}</em>.
Found <strong>${posts.size()}</strong> hits.
</p>
<ul>
<g:each var="tag" in="${posts.tags}">
<li>${tag.Name}</li>
</g:each>
</ul>
<g:link action='search'>Search Again</g:link></body>
</html>
내 질문은 다음과 같이 태그를 표시 할 수 없다는 것입니다.
결과
1 타점을 찾았습니다.
* [planting, dig]
그러나 출력을 다음과 같이 원합니다.
* planting
* dig
여기서 내가 뭘 잘못하고 있니?
매우 감사.
해결책
바꾸다
<g:each var="tag" in="${posts.tags}">
~에 의해
<g:each var="tag" in="${posts.tags[0]}">
제휴하지 않습니다 StackOverflow