Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><em>Tidied up for greater clarity</em></p> <p><code>.trigger()</code> returns a jQuery object so you are denied the option of doing <code>$.when() ... $.then()</code>.</p> <p>On the other hand, <code>.triggerHandler()</code>, will return an object of your choice, thus making it possible to do the deferred trick.</p> <p>Your code is organised in three functions, simplified below. The call path is 1,2,3 and the all-important return path is 3,2,1.</p> <p>(1) The highest level (JSON success) function will include the following lines :</p> <pre><code>function() { ... $.when($('#' + data[0].ID).triggerHandler('click')).done(function() { $.each(data[0].ListEntries, function (key, val) { ... }); }); ... }; </code></pre> <p>(2) The click handler triggered by (1), will be as follows :</p> <pre><code>$("img.Button").on("click", function () { return GetModels(this.id);//here `return` passes on the jqXHR object, up the return path. }); </code></pre> <p>(3) And the lowest level function containing the JSON, on which (1) depends, will be of this general form :</p> <pre><code>function GetModels(id) { ... var jqXHR = getJSON(function(){...}); ... return jqXHR;//it is vital to retutn the jqXHR object arising from the json call. } </code></pre> <p>Notes :</p> <ul> <li>The return path delivers, as the "promise" argument to the <code>.when()</code> method in (1), the jqXHR object arising from the <code>.getJSON()</code> call in (3). The chained <code>.done()</code> in (1) is thus forced to wait for the jqXHR to be resolved (ie. complete) before firing the function that is provided as its argument.</li> <li>The click handler makes no assumptions about how it is invoked. It simply returns the jqXHR object. Thus when invoked with <code>.triggerHandler()</code>, the click handler can have additional behaviour appended to it without affecting the normal click action.</li> <li>It would be simpler to call <code>GetModels()</code> directly from (1), cutting out the middle-man (2), which is fine if <code>GetModels()</code> behaviour is uniquely wanted. If, however, (1) needs to be responsive to any future changes to the triggered click handler (2), then the above approach needs to be adopted.</li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload