Note that there are some explanatory texts on larger screens.

plurals
  1. POAccess Index value while iterating Ember collection
    text
    copied!<p>Trying to access index value while iterating the ember collection, can access index value like this:</p> <pre><code>{{_parentView.contentIndex}} </code></pre> <p>But when trying to access the same index value in compare helper don't see the value. Any help on how to access index inside helper would be appreciated.</p> <p><strong>Code:</strong></p> <pre><code>{{#each App.SampleController}} {{#view App.HomeView contentBinding="this"}} Index : {{_parentView.contentIndex}} {{#compare _parentView.contentIndex "0" operator="=="}} {{/compare} {{/view}} {{/each}} </code></pre> <p>Output:</p> <pre><code>Index: 0 and the value getting passed into compare helper is `_parentView.contentIndex` as a string! </code></pre> <p><strong>Compare Helper looks like this:</strong></p> <pre><code> Ember.Handlebars.registerHelper('compare', function(lvalue, rvalue, options) { if (arguments.length &lt; 3) throw new Error("Handlerbars Helper 'compare' needs 2 parameters"); operator = options.hash.operator || "=="; var operators = { '==': function(l,r) { return l == r; }, '===': function(l,r) { return l === r; }, '!=': function(l,r) { return l != r; }, '&lt;': function(l,r) { return l &lt; r; }, '&gt;': function(l,r) { return l &gt; r; }, '&lt;=': function(l,r) { return l &lt;= r; }, '&gt;=': function(l,r) { return l &gt;= r; }, 'typeof': function(l,r) { return typeof l == r; } }; if (!operators[operator]) throw new Error("Handlerbars Helper 'compare' doesn't know the operator "+operator); console.log("operator is "+ lvalue +" and "+rvalue); var result = operators[operator](lvalue,rvalue); console.log("result from compare registerHelper is "+ result); if( result ) { return options.fn(this); } else { return options.inverse(this); } </code></pre> <p>}); </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