我正在尝试使用 grails 2.2.1 在一个视图上显示一对多的关系。
本质上,我想使用一个视图来显示两个列表(一个父列表,一个子列表)。此外,我想创建对控制器的调用,以根据在父列表中选择的记录在子列表中显示正确的子记录。域看起来像这样......
class Parent{
string name
string attribute
static hasMany = [children : Child]
}
class Child{
string name
string childattribute
static belongsTo = [parent: Parent]
}
父控制器将是...
class AppstackController {
static scaffold = Appstack
def index ={
def parent = Parent.list()
def childList= parent?.child
render(view: "list", model:[parentlist: Parent.list(), childList: childList])
}
def getChildren = {
def parent= Appstack.get(params.id)
def childList= parent?.child
render (view: "list", model:[childList: childList])
}
}
我希望能够调用 getChildren 操作并通过单击父列表中的行来更新视图上的子列表。我认为这可以通过 remoteLink 或 remoteFunction 来完成。
控制器和视图代码应该是什么样子才能完成这个?