1
我有兩個級別的計算屬性的問題。我有點新的燼,所以會讚賞一些指針。Ember.js嵌套屬性計算返回undefined
基本問題是有兩個級別的計算屬性 - 一個在訂單級別,一個在物品級別。訂單等級取決於物料的計算。
綁定到表單後 - 物品級計算效果很好,並且在更改數量時更新表單。然而,訂單總額似乎並沒有計算出來。我在屬性依賴中錯過了什麼嗎?
App.Order = DS.Model.extend({
items: DS.hasMany('item', { async: true }),
payment_cash: DS.attr('number'),
payment_card: DS.attr('number'),
payment_credit: DS.attr('number'),
balance: DS.attr('number'),
total: function() {
return this.get('items').reduce(function(value,lineItem) {
value += lineItem.get('total');
});
}.property("[email protected]"),
itemCount: function() {
return this.get('items').reduce(function(value,lineItem) {
value += lineItem.get('quantity');
});
}.property("[email protected]"),
});
App.Item = DS.Model.extend({
order: DS.belongsTo('item'),
product: DS.belongsTo('product'),
quantity: DS.attr('number'),
adjustment: DS.attr('number'),
total: function() {
return this.get('product.price') * this.get('quantity')
}.property('product.price', 'quantity')
});
App.Product = DS.Model.extend({
name: DS.attr('string'),
description: DS.attr('string'),
price: DS.attr('number'),
imagePath: DS.attr('string')
});
看起來不錯,你把一些日誌扔進了總數?他們被稱爲? – Kingpin2k