jeudi 6 août 2015

Why is @first always false in my handlebars #each loop?

Using Ember.Handlebars, I'm trying to set up a Bootstrap carousel to showcase a selection of issues from my data store.

I want to add the active class on the first item of my carousel, but it sounds like my {{if @first}} test is never evaluated true.

  • My app/templates/issues-list.hbs is :

    <div id="showcase-issues" class="carousel slide">
        <div class="carousel-inner">
            {{#each model.issues as |issue|}}
    
                {{#if @first}}
                <div class="active item">
                    {{#issue-item issue=issue}}{{body}}{{/issue-item}}
                </div>
                {{else}}
                <div class="item">
                    {{#issue-item issue=issue}}{{body}}{{/issue-item}}
                </div>
                {{/if}}
    
            {{/each}}
        </div>
        {{!-- Nav buttons, etc. ... --}}
    </div>
    
    
  • My app/routes/issues-list.js is simply :

    model: function() {
    
        var issues = this.get('store').filter('issue', {
            filters: { "state" : "visible" }
        }, function(item) {
            return (item.get('state') === "visible") ;
        }).then( function(results) {
            return results ;
        }) ;
    
        return Ember.RSVP.hash({issues: issues}) ;
    }
    
    

Did anyone already face this problem ?

Is there a proper way to handle DS.FilteredRecordArrays in a {{#each ...}} helper ?


I'm working with :

  • Ember 1.13.2
  • Ember-data 1.13.5
  • Bootstrap 3.3.5

Thanks a lot for any given hand !




Aucun commentaire:

Enregistrer un commentaire