祝大家新年快乐,
我正在一个项目中,我必须在对话框(模式窗口)窗口的“列表”中显示每个记录的详细信息,同时用户单击列表中每个记录的链接。我正在尝试使用GrailUI插件来完成此任务。这是我的代码:
<gui:dialog width="300px"
controller="tag"
action="showTags"
params=" [id:userInstance.userId]"
update="dialogData"
draggable="true"
triggers="[show:[type:'link', text:'Show Tags', on:'click']]"
modal="true">
<div id='dialogData'>This will be updated by the controller action....</div>
由于某些原因,dialog标签未触发 Controller Action 。它打开对话框窗口,但仅显示此消息“这将通过 Controller 操作...进行更新。”。它没有显示 Controller Action 呈现的输出( View )。有人可以帮助我了解我在做什么错吗?
jQuery和jquery-ui是我在项目中使用的其他插件。
感谢您的帮助。
编辑
def test(Integer max) {
....
....
userInstanceList = User.list(params)
render (view: "test", model: [userInstanceList: userInstanceList, userInstanceTotal: User.count()])
}
def showTags () {
def user = User.findByUserId(params.id)
def tagInstanceList = user.tags
render(view: "test", model: [tagInstanceList: tagInstanceList])
}
最佳答案
如果要将某些内容提交到远程,则需要设置form="true"
。然后,可以在不定义表单的情况下将任何表单元素放置在dialog标记内。当form =“true”时,对话框将创建自己的表单。
这是我测试过的示例:
test.gsp:
<html>
<head>
....
<r:require modules="grailsui-dialog"/>
</head>
<body class="yui-skin-sam">
<gui:dialog width="300px"
controller="test"
action="showTags"
params=" [id:userInstance.userId]"
form="true" <!-- the key to remote submit -->
update="dialogData"
draggable="true"
triggers="[show:[type:'link', text:'Show Tags', on:'click']]"
modal="true" >
<!-- You can put any input element here, which will be submitted in the form-->
<div id='dialogData'>This will be updated by the controller action....</div>
</gui:dialog>
</body>
</html>
测试 Controller :
class TestController {
def test() {
.........
}
def showTags() {
def user = User.findByUserId(params.id)
def tagInstanceList = user.tags
render(template: "ajaxResponse", model: [tagInstanceList: tagInstanceList, user:user]) //render a template, not a view
}
对于Ajax请求,您无法呈现 View ,它将替换原始页面。相反,您应该发回一个模板,其中包含要在对话框中显示的标签:
_ajaxResponse.gsp
<h3>Tag List of user ${user.username}</h3>
<g:each in="${tagInstanceList}" var="tag">
<p>${tag}</p>
</g:each>
关于grails - Grails UI(插件)对话框未触发 Controller 操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14116066/