简体   繁体   English

Grails remoteField-我可以调用渲染/重定向吗?

[英]Grails remoteField - Can I call a render/redirect?

I'm not looking for a div update. 我不是在寻找div更新。 I'm looking for a full page "refresh" 我正在寻找整页“刷新”

So I have a tag: 所以我有一个标签:

<g:remoteField controller="person" action="updatePerson" id="${personInstance.id}" paramName="search" name="updatePerson" value="${personInstance?.favoriteBreed}" />

In my attached method, I want to perform the action of updating the domain object, then refresh the entire page. 在我的附加方法中,我要执行更新域对象的操作,然后刷新整个页面。 I've tried both renders and redirects to simple actions within the application, but nothing is called. 我已经尝试过渲染和重定向到应用程序内的简单操作,但是什么也没叫。 So I'm thinking this isn't possible with the remoteField tag. 因此,我认为使用remoteField标签是不可能的。

Is this true? 这是真的?

<g:remoteField /> have the event onSuccess that can be used to do what you want. <g:remoteField />具有事件onSuccess ,可用于执行您想要的操作。 You can check more options here . 您可以在此处检查更多选项。

Try (not tested): 尝试(未测试):

<g:remoteField controller="person" action="updatePerson" 
    id="${personInstance.id}" paramName="search" name="updatePerson"    
    value="${personInstance?.favoriteBreed}" onSuccess="reloadPage()" />

And you will need to create the javascript function: 您将需要创建javascript函数:

function reloadPage() {
  window.location.reload();
}

Why reimplementing via AJAX the normal behaviour of a page? 为什么要通过AJAX重新实现页面的正常行为? Why don't you just call a redirect to the right action at the end of the called controller? 您为什么不只在被调用控制器的末尾调用重定向到正确操作的方法?

Let's say you are in the view resulted from the showPerson action. 假设您处于showPerson动作产生的视图中。 In this view, call the updatePerson with a simple (don't care about the params attribute, it's only an example): 在此视图中,用一个简单的调用updatePerson(不必关心params属性,它只是一个示例):

<g:Link controller="person" action="updatePerson" id="${personInstance.id}" params="${name: 'search'}">click me</g:link>

and in the controller do something like: 并在控制器中执行以下操作:

def updatePerson = {
  // your own updating stuff

  redirect(action: "show", id: person.id)
}

Isn't it easier? 难道不是很容易吗? :) :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM