Ember computed equal 不适用于 ember-mirage

Ember computed equal not working with ember-mirage

我试图将产品分为两类,零食和分享,但我的 computed.equal 不工作。我目前没有连接数据库,所以我正在使用 ember-mirage 来伪造数据。如果我删除 if 语句,产品会显示在页面上,但由于某种原因,当我添加 if 语句时,产品不会显示在页面上。提前致谢。

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>

model/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: ''
      }
    }
  }]
 };
});

在你的海市蜃楼响应中,你应该使用虚线化的值,所以即 { type: 'products', id:2, attributes: { name: "Spicy Snack Pop's", 'type-of': 'share', description: '', price: 0.80, image: '' }