Pregunta

I am wondering if there is a way that I can get the current element that is triggering the onBeforeChangeEvent function in jsViews. I want to get the current element that it is working on, to do some extra jQuery work on it.

A basic example is below:

  $.views.helpers({
    onAfterChange: function (ev)
    {

        //want to get element instance right here as an example.....
        if (!PageSettings.cancelUpsert && ev.type == "change")
        {
             //do somthing to element that is currently being processed.
        }
    }
  });

I searched through the objects being returned, but could find a stable way to get to the element. Any ideas, or tips towards where to look would greatly be appreciated. Thanks!

¿Fue útil?

Solución

If you are looking for a data-linked element, such as an input: <input data-link="..." />, whose change event triggered the change, you can get that from either this.linkCtx.elem or ev.target.

More generally, the this pointer is the view object that is being changed.

There are a number of helper methods on the view object that you can use to access different elements within that view. For example this.contents("someSelector") will return a jQuery object that selects top-level elements in that view, and this.contents(true, "someSelector") will apply the selector to filter on all elements in the view (deep search not just top-level).

(You can use the selector "*" to get all elements)

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top