0
我試圖將產品分爲兩類,小吃和共享,但我的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>
模型/ 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')
});
海市蜃樓/ 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: ''
}
}
}]
};
});
謝謝 – d9nny