0

Are there any tags that support databinding other than select? . I use it for one to many relationships

It seems impractical if you have lots of data and scrolling will be longer

It would be awesome if its just a list of checkboxes then there will be a pagination

4

1 回答 1

0

g.select只是 Grails 的默认设置,但您可以自定义视图并使用任何元素,因为信息就在那里。例子:

class Parent {
  String name
  static hasMany = [childrens: Child]
}

class Child {
  String name
}

class ParentController {
  def create() {
    Parent parentInstance = new Parent()
    List<Children> childrens = Children.list()
    [parentInstance : parentInstance, childrens: childrens]
  }

  def save() {
    def childrens = params.list('childrens')
    println childrens //will output all checkbox marked...
  }

}

form.gsp

<ul>
<g:each in="${childrens}" var="child">
  <li><g:checkBox name="childrens" value="${child in parentInstance.childrens}" /></li>
</g:each>
</ul>

这里的一些关键点:

  • 如果你hasMany方可以有很多记录,你可以重新考虑这种方法;
  • 您的所有复选框必须具有相同的名称才能被视为列表;
  • 更新 Parent 时,您需要在添加新关系之前删除关系;

相关主题:Grails - 简单的 hasMany 问题 - 在 create.gsp 中使用 CheckBoxes 而不是 HTML Select

于 2013-09-30T16:25:33.960 回答