我在使用标签时遇到性能问题。在数据库中的某些表中,我有数千条记录,当我尝试在Grails中编辑某个字段时,该标记会生成表格中所有记录的下拉列表,并且会导致真正的性能问题,甚至有时会导致EndOfMemorryError。生成的html是巨大的,我试图实现一个自动完成的方法上市,但结果并不令人满意,因为我想这是一个全球性的解决方案,我的300个Java类,如果我使用自动完成我不得不写它的我的每一个类,现在我的想法是尝试改变下拉列表与弹出窗口显示记录使用分页。我beleive我必须改变这种代码在renderEditor.template:Grails脚手架选择
private renderManyToOne(domainClass,property) {
if (property.association) {
def sb = new StringBuilder()
sb << '<g:select'
// id is "x" and name is "x.id" as the label will have for="x" and "." in an id will confuse CSS
sb << ' id="' << property.name << '"'
sb << ' name="' << property.name << '.id"'
sb << ' from="${' << property.type.name << '.list(max: 10, offset: offset)}"'
sb << ' optionKey="id"'
if (isRequired()) sb << ' required=""'
sb << ' value="${' << "${domainInstance}?.${property.name}" << '?.id}"'
sb << ' class="many-to-one"'
sb << renderNoSelection(property)
sb << '/>'
sb as String
}
}
任何想法可以理解的:)
FWIW,有*威力*(半信半疑,但有可能)是现有的[约束部件(http://grails.org/doc/2.0.x/ref/Constraints/ widget.html),这将帮助你。但是,我不知道可能的小部件列表是什么。我[为这个问题添加了一个赏金](http://stackoverflow.com/questions/7295811/what-widget-constraints-are-valid-for-grails-domain-classes)希望能够得出答案。 –