最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to get source element from AJAX event? - Stack Overflow

programmeradmin0浏览0评论

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>

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

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

Surely it doesn't contain source attribute, as that link would suggest: .php?f=3&t=14871

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

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>

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

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

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

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

Share Improve this question asked Apr 8, 2014 at 12:50 Cjxcz OdjcayrwlCjxcz Odjcayrwl 22.9k43 gold badges149 silver badges231 bronze badges 1
  • Note that in pure JSF (f:ajax) you can access the id of the calling element by using data.source.id – Daniel Commented Apr 8, 2014 at 13:17
Add a ment  | 

1 Answer 1

Reset to default 6

You can pass the event instead....

XHTML

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

JS

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

The object that you are referring in the question is PrimeFaces.ajax.AjaxUtils.

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]);']);

Hope this helps.

发布评论

评论列表(0)

  1. 暂无评论