如何从AJAX事件中获取源元素? [英] How to get source element from AJAX event?

查看:98
本文介绍了如何从AJAX事件中获取源元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个控件行的表。我希望在输入更改时处理行中的其他元素:

I have a table with controls in rows. I want to process another elements in the row when the input is changed:

        <p:inputText value="#{item.text}">
          <p:ajax event="change" onstart="refreshColumn(this)"/>
        </p:inputText>

但是,'this'是我在这里无法识别的:

However, 'this' is something that I can't identify here:


Object {encodeViewState = function(),updateState = function(),updateElement = function(),mehr ...}

Object { encodeViewState=function(), updateState=function(), updateElement=function(), mehr...}

当然它不包含 source 属性,因为该链接会建议: http://forum.primefaces.org/viewtopic.php?f=3&t=14871

Surely it doesn't contain source attribute, as that link would suggest: http://forum.primefaces.org/viewtopic.php?f=3&t=14871

是否有可能(如何)从获取触发事件的元素p:ajax 回调?

Is it possible (how) to get the element that triggered the event from p:ajax callbacks?

推荐答案

您可以传递事件而不是....

You can pass the event instead....

XHTML

XHTML

<p:inputText value="#{item.text}">
   <p:ajax event="change" onstart="refreshColumn(event)"/>
</p:inputText>

JS

JS

function refreshColumn(event) {
   // "event.target.id" is the id of the inputText
   console.log(event.target.id)
}






您在问题中引用的对象是 PrimeFaces.ajax.AjaxUtils

PrimeFaces ajax /回调函数是 PrimeFaces.Behavior s。

The PrimeFaces ajax/callback functions are PrimeFaces.Behaviors.

至于你可以传递的更多信息:

As for what you can pass more:

PrimeFaces.bc = function(source, event, ext, behaviorsArray) {
    PrimeFaces.Behavior.chain(source, event, ext, behaviorsArray);
}

更改事件的输出应该是这样的(仅传递事件) :

The output of the change event should be something like this (passing only event):

PrimeFaces.bc(this, event, ext, ['PrimeFaces.ab({source:\'form:inputId\',event:\'change\',process:\'form:inputId\',onstart:function(cfg){refreshColumn(event);}}, arguments[1]);']);

希望这有帮助。

这篇关于如何从AJAX事件中获取源元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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