非常长的模板/视图上的方法代码长度无效
我有一个很长的报告模板。它同时包含 50 多个 Grails 域。但是当我尝试加载最多 25 个域时,它显示“方法代码长度无效”。我在谷歌上进行了搜索,它建议我拆分/丢弃模板。
所以我做了以下更改:
之前是一个模板 _template.gsp
但现在: _template.gsp 和 _template2.gsp
但在 _template.gsp 中我放置了诸如
现在问题之类的代码它不允许加载已加载的模型/对象在控制器中进入 template2 ....
在我的控制器中:
Class AbcController{
def index = {
def myParrent = MyParrent.get(1);
def mode = [:];
model.obj1 = Obj.findAllByParrent(myParrent);
model.obj2 = Obj2.findAllByParent(myParrent);
...
model.obj50 = Obj50.findAllByParrent(myParrent);
model.obj51 = Obj51.findAllByParent(myParrent);
def str = render(template:"template", model:model);
render(str);
}
}
知道为什么模型加载到 _template.gsp 中但在 _template2.gsp 中无法识别
编辑:
_template.gsp 会喜欢这个(不像这个那么简单,因为对于每个域对象我必须一一显示它的字段)
<html><body>
<div>${obj1}</div>
<div>${obj2}</div>
<div>${obj3}</div>
....
<div>${obj24}</div>
<div>${obj25}</div>
......
<g:render template="template2"/>
.....
</body></html>
_template2.gsp:
<div>${obj26}</div>
<div>${obj27}</div>
<div>${obj28}</div>
........
<div>${obj50}</div>
所以在一个页面中我想一次显示大约50个域(目的是为了填写表单,所以如果我必须显示所有域,请不要怪我)一次数据...)
谢谢
I have a very long templates for report. It contains more than 50 Grails domain at once. But when I tried to load up to 25 domain, it said "Invalid method Code length". I did search on google and it recommend me to split / chuck the templates.
So I made the following changes:
before it was one template _template.gsp
but now : _template.gsp and _template2.gsp
but inside _template.gsp I put code such as
Now the problem It won't allow to load model/objects that loaded in controller into template2 ....
in my controller:
Class AbcController{
def index = {
def myParrent = MyParrent.get(1);
def mode = [:];
model.obj1 = Obj.findAllByParrent(myParrent);
model.obj2 = Obj2.findAllByParent(myParrent);
...
model.obj50 = Obj50.findAllByParrent(myParrent);
model.obj51 = Obj51.findAllByParent(myParrent);
def str = render(template:"template", model:model);
render(str);
}
}
any idea why model loaded in _template.gsp but not recognized in _template2.gsp
edit:
_template.gsp would like this one (not as simple as this one, because for each domain object I have to display one by one its fields)
<html><body>
<div>${obj1}</div>
<div>${obj2}</div>
<div>${obj3}</div>
....
<div>${obj24}</div>
<div>${obj25}</div>
......
<g:render template="template2"/>
.....
</body></html>
_template2.gsp:
<div>${obj26}</div>
<div>${obj27}</div>
<div>${obj28}</div>
........
<div>${obj50}</div>
So in a page I would like to display about 50 domain at once (the purpose is for filling the form, so don't blame me if I have to display all the data at once ... )
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要将模型传递到另一个模板中:
You need to pass the model(s) into the other template: