【问题标题】:Grails render view with objects from other domainsGrails 使用来自其他域的对象渲染视图
【发布时间】:2018-04-13 02:02:18
【问题描述】:

我有两个相关的域对象。

首先是:

class VideoCategory {

    String videoCategoryName

    static constraints = {
        videoCategoryName nullable: false
    }
}

那么我有:

class Video {

    VideoCategory videoCategory
    String fileName
    String videoTitle
    String videoDescription

    static constraints = {
        fileName nullable: false
        videoTitle nullable: true
        videoDescription nullable: true
    }
}

我想要的是一个视频的创建页面,它不会显示来自 VideoCategory 对象的 videoCategoryId,而是显示脚手架下拉列表中的 videoCategoryName 本身。我想将 id 用作 FK,但呈现名称......然后在保存时我想保存 id。我对 Java/Groovy 的思维方式很陌生。在 python/flask 中,我可能只是确保将所有对象都导入到我的视图中,然后我可以直接调用它们并使用该数据 render_view 然后嵌入 id 作为保存的值,同时将 videoCategoryName 值呈现在标记。

【问题讨论】:

    标签: grails


    【解决方案1】:

    将此添加到 VideoCategory 类:

    String toString() {
        return videoCategoryName
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-06
      • 1970-01-01
      • 1970-01-01
      • 2014-01-21
      • 2013-03-31
      • 2013-06-15
      相关资源
      最近更新 更多