2016-05-31 10 views
0

Ich versuche, Produkte in zwei Kategorien, Snack und teilen, aber meine computed.equal funktioniert nicht. Ich habe momentan keine Datenbank angeschlossen, also verwende ich ember-mirage, um die Daten zu fälschen. Die Produkte werden auf der Seite angezeigt, wenn ich die if-Anweisung entferne, aber aus irgendeinem Grund nicht, wenn ich die if-Anweisung hinzufüge. Danke im Voraus.Ember berechnet gleich funktioniert nicht mit Ember-Mirage

products.hbs

<div class='container'> 
     {{#each model as |product|}} 
      {{#if product.isSnack}} 
       <div class='col-md-4'> 
        <img src="{{product.image}}"> 
        <h3>{{product.name}}</h3> 
        <p>{{product.description}}</p> 
        <h4>£{{product.price}}</h4> 
        <button type='button' class='btn btn-xs'>ADD TO BASKET</button> 
       </div> 
      {{/if}} 
     {{/each}} 
    </div> 

Modell/product.js

export default Model.extend({ 

name: attr('string'), 
description: attr('string'), 
typeOf: attr('string'), 
price: attr('number'), 
image: attr('string'), 

isSnack: Ember.computed.equal('typeOf', 'snack'), 

isShare: Ember.computed.equal('typeOf', 'share') 

}); 

mirage/config.js

this.get('/products', function() { 
    return { 
    data: [{ 
     type: 'products', 
     id:1, 
     attributes: { 
     name: "Mediterranean Snack Pop's", 
     typeOf: 'snack', 
     description: '', 
     price: 0.80, 
     image: '' 
     } 
    }, { 
     type: 'products', 
     id:2, 
     attributes: { 
     name: "Spicy Snack Pop's", 
     typeOf: 'share', 
     description: '', 
     price: 0.80, 
     image: '' 
     } 
    } 
    }] 
}; 
}); 

Antwort

1

In Ihrem mirage Antwort, sollten Sie Dasher Werte verwenden, so dh { type: 'products', id:2, attributes: { name: "Spicy Snack Pop's", 'type-of': 'share', description: '', price: 0.80, image: '' }

+0

Hat den Job Danke gemacht – d9nny