Grails - 如何在更改选择后更新 GSP?
我编写了一个域类并搭建了控制器和视图。我稍微修改了 list.gsp 和列表操作。为了过滤显示的内容,我在页面上放置了 ag:select 标签。
每当选择中的值发生更改时,列表控制器就会再次触发并过滤返回的数据实例。这就像一个魅力。
问题是我无法显示更改后的实例;我知道更新 GSP 的唯一方法是执行 window.location.reload() ,但这会导致页面重新初始化。所以一切都恢复到默认状态。
那么问题来了:如何让我的 GSP 获取更改后的实例数据并显示它?
例如,选择其中之一。返回的实例将通过选定的月份和年份变量进行过滤。
<g:select id="monthSelection" from="${['Jan', 'Feb', 'Mrt', 'Apr', 'Mei', 'Jun', 'Jul', 'Aug', 'Sep', 'Okt', 'Nov', 'Dec']}" value="${inputYear}" onchange="${remoteFunction(
action:'list',
params:'\'selectedYear=\' + escape(yearSelection.value) +\'&selectedMonth=\' + escape(this.value)'
)}"
"/>
谢谢!
I have written a domain class and scaffolded the controller and the views. I've modified the list.gsp and list action a bit. To filter what's displayed, I've put a g:select tag on the page.
Whenever the value in the select is changed, the list controller is fired again and filters the data instance returned. This works like a charm.
Thing is that I can't display the changed instance; the only way I know to update the GSP is to do a window.location.reload() but that results in a re-initialization of the page. So everything is back to default.
So here is the question: how can I make my GSP pick up the changed instance data and display that?
For example, one of the selects. The returned instance is filtered though the selected month and year variables.
<g:select id="monthSelection" from="${['Jan', 'Feb', 'Mrt', 'Apr', 'Mei', 'Jun', 'Jul', 'Aug', 'Sep', 'Okt', 'Nov', 'Dec']}" value="${inputYear}" onchange="${remoteFunction(
action:'list',
params:'\'selectedYear=\' + escape(yearSelection.value) +\'&selectedMonth=\' + escape(this.value)'
)}"
"/>
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
听起来您要么需要
remoteFunction
方法以使其返回模板视图,然后设置update
参数指定页面上的哪个 div 应使用返回视图中的内容进行动态更新。remoteFunction
调用上的我在一些需要 ajax 更新的情况下使用过选项 2,并且效果很好。
Sounds like you either need to
remoteFunction
method so that it returns a template view, and set theupdate
parameter on theremoteFunction
call to specify which div on the page should get dynamically updated with the content from the returned view.I've used option 2 in several cases where I needed an ajax update and it worked nicely.
尝试这样的操作:
这里的“divId”应该包含在使用列表操作进行ajax调用后需要更新的html部分。
喜欢 :
Try out something like this :
Here 'divId' should contains the html portion that you needs to update after an ajax call with list action.
Like :