Grails 域内的域
我有两个域类:-Grails 域内的域,grails,groovy,Grails,Groovy,我有两个域类:- class Product { ProductType productType int openingQuantity int unitQuantity Date dateCreated Date lastUpdated boolean active static constraints = { productType(blank:false,nullable:false) openingQuantity(blank:false, n
class Product {
ProductType productType
int openingQuantity
int unitQuantity
Date dateCreated
Date lastUpdated
boolean active
static constraints = {
productType(blank:false,nullable:false)
openingQuantity(blank:false, nullable:false)
unitQuantity(blank:false, nullable:false)
active(nullable:false)
dateCreated()
lastUpdated()
}
}
及
当我在create.gsp的产品。它在下拉列表中将productType显示为id。但我的要求是在下拉列表中显示ProductType名称。任何人都可以提供帮助。您可以在ProductType类上重写toString
String toString() { name }
或者,假设您使用的是默认脚手架,请更改:
<g:select name="productType.id"
from="${com.ten.hp.his.pharmacy.ProductType.list()}"
optionKey="id"
value="${productInstance?.productType?.id}" />
您可以覆盖ProductType类上的toString
String toString() { name }
或者,假设您使用的是默认脚手架,请更改:
<g:select name="productType.id"
from="${com.ten.hp.his.pharmacy.ProductType.list()}"
optionKey="id"
value="${productInstance?.productType?.id}" />
是的,我可以做,但我不想在域名上做。您能推荐一些视图中的内容吗?@AB您当前使用哪些标签来显示视图中的字段?如果您希望在那里应用更改,那么视图的代码可能会有所帮助(而不仅仅是发布您的域)。这是默认生成的脚手架。它将产品类型id显示为下拉列表。@AB将
optionValue=“name”
添加到g:select
Yes我可以这样做,但我不想在域中这样做。您能推荐一些视图中的内容吗?@AB您当前使用哪些标签来显示视图中的字段?如果您希望在那里应用更改,那么视图的代码可能会有所帮助(而不仅仅是发布您的域)。这是默认生成的脚手架。它将产品类型id显示为下拉列表。@AB将optionValue=“name”
添加到g:select