Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><code>{{:#data}}</code> renders #data as a string, so <strong>that approach won't work unless #data stringifies and parses neatly</strong>. Objects won't stringify or parse neatly without manual JSON usage. In fact, I suspect only numbers, booleans, <code>undefined</code>, and <code>null</code> will stringify and parse correctly. That approach <strong>also</strong> won't work <strong>if the function is not global</strong>. Being forced to define the callback function globally any time you want to do this strikes me as a severe problem. So I can't recommend using in-tag event-handlers, especially when you already have JavaScript running.</p> <p><strong>Instead</strong>, after you insert your rendered content into the DOM, you can bind the event there. Here's a rough sketch.</p> <p>Add a class or some other selector-fodder to your <code>&lt;li&gt;</code>.</p> <pre><code>&lt;li class="onMouseEnter" id="liv_{{:nid}}"&gt;&lt;/li&gt; </code></pre> <p>Put each of your #data values into an object using an equivalent of <code>liv_{{:nid}}</code> as the key.</p> <pre><code>var dataMap = {}; $.each(yourDataValues, function (i, value) { dataMap['liv_' + value.nid] = value; }); </code></pre> <p>Lastly, bind a live event to the container into which you pushed your rendered template.</p> <pre><code>$(containerOfRenderedTemplate).on('mouseenter', '.onMouseEnter', function () { var id = $(this).attr('id'); var data = dataMap[id]; desiredCallbackFunctionWhichConsumesData(data); }); </code></pre> <p><code>dataMap</code> and the event-binding call should be within the same scope.</p> <p><strong>Note:</strong> If this rendering can happen more than once, and you need to replace the rendered content with all-new rendered content, you should unbind the old event before binding the new one.</p> <pre><code>$(containerOfRenderedTemplate).off('mouseenter', '.onMouseEnter'); </code></pre>
    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. This table or related slice is empty.
    1. This table or related slice is empty.
    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