我有一个包含模板和外观的实例表单。 要创建一个新表单,我有一个带有2个下拉列表的视图,其中包含模板和外观。现在我想将模板和外观限制为当前登录用户拥有的模板和外观。
我正在使用tostring方法格式化下拉列表。
答案 0 :(得分:2)
在您的控制器中,您需要查询经过身份验证的用户的数据。假设您的Template.groovy看起来像这样:
class Template {
String name
static belongsTo = [owner: User]
}
然后在控制器的动作中:
def create() {
def authenticatedUser = .... // however you get the logged in user
def templates = Template.findAllByOwner(authenticatedUser)
[templates: templates]
}
然后在你的create.gsp:
<g:select from="${templates} ... />
显然,为Appearance做同样的事情。