javascript - Getting the model inside a controller emberjs -


i need grand total price of objects returned json api.

my idea create controller , set property on it. grab model loop on each object , add predefined property objects total price. this:

export default ember.controller.extend({     ordertotal: 0,      getordertotal: function(){         var model = this.get('model');          model.foreach(function(c){             var order_total = this.get('ordertotal') * c.total_price;             this.set('ordertotal', order_total)         });     } }); 

problem can't model. how can access model inside controller?

the model loaded asynchronously, therefore have use .then(...) wait model being loaded.

this.get('model').then(function(data) { ... create sum using `data` }); 

though use computed properties create sum of can potentially change:

allprices: ember.computed.mapby('model', 'price'), totalprice: ember.computed.sum('allprices') 

http://emberjs.jsbin.com/wiwiqulozi/1/


Comments

Popular posts from this blog

javascript - Bootstrap Popover: iOS Safari strange behaviour -

Magento/PHP - Get phones on all members in a customer group -

session - Logging Out Using PHP -