简体   繁体   English

灰烬计算得出的相等值不适用于ember-mirage

[英]Ember computed equal not working with ember-mirage

I'm trying to split products into two categories, snack and share, but my computed.equal isn't working. 我正在尝试将产品分为零食和共享两类,但是我的compute.equal无法正常工作。 I don't have a database connected at the moment, so I'm using ember-mirage to fake the data. 我目前没有连接数据库,所以我正在使用ember-mirage伪造数据。 The products show on the page if I remove the if statement, but for some reason don't when I add the if statement. 如果删除if语句,产品将显示在页面上,但是由于某些原因,当添加if语句时产品不会显示。 Thanks in advance. 提前致谢。

products.hbs 产品.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 型号/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 海市rage楼/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: ''
      }
    }
  }]
 };
});

在Mirage响应中,应使用反斜线值,即{ type: 'products', id:2, attributes: { name: "Spicy Snack Pop's", 'type-of': 'share', description: '', price: 0.80, image: '' }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM