Note that there are some explanatory texts on larger screens.

plurals
  1. POStrange results with nested handlebar blocks in Meteor
    text
    copied!<p>I am trying to set default value in an html select, but without sucess. I'm doing the initial populating like this:</p> <pre><code>&lt;template name="demo"&gt; &lt;select&gt; {{#each foo}} &lt;option&gt;{{this}}&lt;/option&gt; {{/each}} &lt;/select&gt; &lt;/template&gt; </code></pre> <p>And i set the possible options in the model like this:</p> <pre><code>Template.demo.foo = ["aaa","bbb","ccc"]; </code></pre> <p>So far, everything work as intended.</p> <p>Now i'm trying to display row of the collection collec, populating the select with the defaut recorded foo value (aaa or bbb or ccc). My understanding is that you must add "selected" to the tag. So i do something like this with multiple nested blocks:</p> <pre><code>&lt;template name="demo"&gt; {{#each collecs}} {{_id}} &lt;select&gt; {{#each foos}} &lt;option{{#if isSelected this ../this}}selected{{/if}}&gt;{{this}}&lt;/option&gt; {{/each}} &lt;/select&gt; {{/each}} &lt;/template&gt; </code></pre> <p>And on the model front:</p> <pre><code>Template.demo.foos = ["aaa","bbb","ccc"]; Template.demo.collecs = function(){ return Collec.find({}); }; Template.demo.isSelected = function(fooToCheck, record){ var rid= record._id; var currentRecord = Collec.findOne({_id:rid}); return (fooToCheck==currentRecord.foo); }; </code></pre> <p>The problem is that it does not work. The dropdown stays empty, and the generated html code show something like this:</p> <pre><code>" &gt;aaa " </code></pre> <p>I have checked in the js part, all seems to work correctly, true/false are adequately returned.</p> <p>Thank in advance for your help.</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