Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
get/set
import Ember from 'ember';
const { get, set } = Ember;
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
log(object, type) {
console.log(`the thing: ${object} from ${type}`);
},
init() {
let objects = [];
// make an array of POJOs
for (var i = 0; i < 11; i++) {
objects.push({ foo: `bar ${i}` });
}
// create an array of Ember objects
let emberObjects = objects.map((object) => Ember.Object.create(object));
// iterate through Ember objects, using `object.get`
emberObjects.forEach((object) => {
const foo = object.get('foo');
this.log(foo, object.toString());
});
/*
// iterate through POJOs using `object.get` :bomb emoji:
objects.forEach((object) => {
const foo = object.get('foo');
this.log(foo);
});
*/
/*
// iterate through POJOs using `Ember.get` :100 emoji:
objects.forEach((object) => {
const foo = get(object, 'foo');
this.log(foo, 'POJO');
});
// iterate through Ember objects using `Ember.get` :100 emoji:
emberObjects.forEach((object) => {
const foo = get(object, 'foo');
this.log(foo, object.toString());
});
*/
}
});
<h1>Welcome to {{appName}}</h1>
<br>
<br>
{{outlet}}
<br>
<br>
{
"version": "0.7.1",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"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.4.3/ember.debug.js",
"ember-data": "https://cdnjs.cloudflare.com/ajax/libs/ember-data.js/2.4.3/ember-data.js",
"ember-template-compiler": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/2.4.3/ember-template-compiler.js"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment