将源HTML元素传递给PrimeFaces p:ajax的oncomplete函数 [英] Pass source HTML element to oncomplete function of PrimeFaces p:ajax

查看:70
本文介绍了将源HTML元素传递给PrimeFaces p:ajax的oncomplete函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将源HTML元素作为参数传递给<p:ajax oncomplete>的JavaScript回调函数.我尝试传递通常在onclick中工作的this,例如:

I would like to pass the source HTML element as argument to JavaScript callback function of <p:ajax oncomplete>. I tried passing this which usually works in onclick and such:

<p:ajax ... oncomplete="callbackFunction(this)" />

它不起作用.似乎是另外一个对象.

It's not working. It seems to be a different object.

我该如何实现?

推荐答案

oncomplete的上下文中,this表示PrimeFaces ajax对象,该对象实际上包含许多信息.您可以通过在调试器中检查对象或传递给console.log来自动找出漂亮的JS对象,从而很容易地发现它.

In context of oncomplete, the this represents the PrimeFaces ajax object which actually contains a lot of information. You could easily have figured out it by inspecting the object in debugger, or by passing to console.log which automatically pretty prints JS objects.

function callbackFunction(arg) {
    console.log(arg);
}

如果是..

<h:form id="formId">
    <h:commandLink id="linkId" value="test">
        <p:ajax oncomplete="callbackFunction(this)" />
    </h:commandLink>
</h:form>

..它在控制台中看起来像这样(按F12键到达那里):

.. it'll look something like this in console (press F12 to get there):

accepts: Object
async: true
beforeSend: (w,i)
cache: false
complete: (w,i)
contentType: "application/x-www-form-urlencoded; charset=UTF-8"
contents: Object
converters: Object
crossDomain: false
data: "javax.faces.partial.ajax=true&javax.faces.source=formId%3AlinkId&javax.faces.partial.execute=formId%3AlinkId&javax.faces.behavior.event=action&javax.faces.partial.event=click&formId=formId&javax.faces.ViewState=-4870787666399983047%3A-2006040112896840046"
dataType: "xml"
dataTypes: Array[2]
error: (x,i,w)
flatOptions: Object
global: false
hasContent: true
isLocal: false
jsonp: "callback"
jsonpCallback: ()
portletForms: null
processData: true
responseFields: Object
source: a#formId:linkId
success: (x,i,y)
type: "POST"
url: "/playground/test"
xhr: bD()
__proto__: Object

如果您仔细看,则最终需要source属性.

If you look closer, the source property is what you ultimately need.

因此,只需相应地更改您的通话即可:

So, just alter your call accordingly:

<p:ajax ... oncomplete="callbackFunction(this.source)" />

这篇关于将源HTML元素传递给PrimeFaces p:ajax的oncomplete函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆