Note that there are some explanatory texts on larger screens.

plurals
  1. PODerby.js - adding/removing unique list elements
    text
    copied!<p>I have this as my bootstrapped data, which I push to the model when nothing is retrieved from the DB:</p> <pre><code>var liveaudience = { triggers : [ { 'trigger_id': 'vocal_stomp', 'duration': 1000, 'color': '#F23000', 'sound': 'A#' }, { 'trigger_id': 'guitar_stomp', 'duration': 600, 'color': '#CC0234', 'sound': 'Cmaj' }, { 'trigger_id': 'drum_pad', 'duration': 1200, 'color': '#CF2451', 'sound': 'Emin' } ] }; </code></pre> <p>I have this one route, which does this and then renders these three bootstrapped elements on the template:</p> <pre><code>get('/:triggerId?', function(page, model, params){ var triggers = model.get('liveaudience.triggers'); if(typeof triggers === 'undefined'){ // bootstrap triggers model.push('liveaudience.triggers', liveaudience.triggers); } model.subscribe("liveaudience.triggers", function(err, scopedModels){ page.render({'triggers': scopedModels.get()[0]}); }); }); </code></pre> <p>and then here is the template:</p> <pre><code>&lt;ul id="triggers"&gt; {{#each triggers}} &lt;li data-id="{{id}}" class="trigger" style="background-color:{{color}};"&gt; &lt;span class="trigger-label"&gt;{{trigger_id}}&lt;/span&gt; &lt;a x-bind="click:removeTrigger" class="remove-trigger"&gt;x&lt;/a&gt; &lt;/li&gt; {{/}} &lt;/ul&gt; </code></pre> <p>Everything shows up, but {{id}} returns a function, and I'd like it to be a uniquely assigned <a href="http://derbyjs.com/#guids" rel="nofollow">GUID</a>. The main issue is that I don't know how to get &amp; remove this element from the DOM when clicking and firing the <code>removeTrigger</code> handler. Looking at examples, I've seen this within the handler:</p> <p><code>model.at(e.target).remove();</code></p> <p>but that doesn't work.</p> <p>Any ideas?!</p>
 

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