【发布时间】:2014-10-23 16:46:16
【问题描述】:
我有以下 POJO/POGO:
class Person {
String firstName
String lastName
int age
// ... lots of other fields
}
还有一个 Grails 2.3.6 控制器:
class PeopleController {
List<Person> people = new ArrayList<Person>()
def populatePeople() {
// Add lots of people to the 'people' list.
}
def doSomething() {
populatePeople()
render(
view: "people",
model:[
people: people,
]
)
}
}
然后在普惠制中:
<div id="peopleSelector">
<g:select name="people" from="${people}" />
</div>
当我运行我的应用程序时,我得到了 <select> 元素,其 com.me.myapp.domain.Person@398r4d99 外观值为 <option>s。这显然是 Grails 没有将我的 Person 实例反序列化为漂亮的打印形式。
我希望人们的名字和姓氏显示为选择选项。因此,如果people 列表中的Person 实例之一是:
Person smeeb = new Person(firstName: "Smeeb", lastNname: "McGuillocuty")
然后我希望“Smeeb McGuillocuty”作为最终 HTML 中的选择选项。 我怎样才能做到这一点?
【问题讨论】:
标签: grails model-view-controller groovy grails-controller