Skip to content

Instantly share code, notes, and snippets.

@jansegre
Created March 1, 2016 17:30
Show Gist options
  • Save jansegre/b663f3affd09d4491270 to your computer and use it in GitHub Desktop.
Save jansegre/b663f3affd09d4491270 to your computer and use it in GitHub Desktop.
Store Example
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
orders: null,
init() {
this.set('orders', this.get('store').findAll('order'));
}
});
<h1>{{appName}}</h1>
<br>
<br>
{{#each orders as |order|}}
{{else}}
No order.
{{/each}}
<br>
<br>
import DS from 'ember-data';
import Ember from 'ember';
export default DS.Model.extend({
product_type: DS.belongsTo('product'),
order: DS.belongsTo('order'),
quantity: DS.attr('number', { defaultValue: 0 }),
item_price: Ember.computed('product_type.price', 'quantity', function() {
const p = this.get('product_type').get('price');
const q = this.get('quantity');
return p * q;
}),
});
import DS from 'ember-data';
import Ember from 'ember';
export default DS.Model.extend({
products: DS.hasMany('order-item'),
total_price: Ember.computed('[email protected]_price', function() {
let s = 0.0;
this.get('products').forEach(p => { s += p.get('item_price') });
return s;
}),
});
import DS from 'ember-data';
export default DS.Model.extend({
price: DS.attr('number'),
});
{
"version": "0.6.0",
"EmberENV": {
"FEATURES": {}
},
"options": {
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/2.3.1/ember.debug.js",
"ember-data": "https://cdnjs.cloudflare.com/ajax/libs/ember-data.js/2.3.3/ember-data.js",
"ember-template-compiler": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/2.2.0/ember-template-compiler.js"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment