Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
ember enumerables
import Ember from 'ember';
export default Ember.Object.extend({
name: 'abb'
});
import Ember from 'ember';
import A from './AModel';
export default Ember.Component.extend({
value1: Ember.computed.oneWay('value'),
arr: [],
actions: {
addObjectInArr() {
this.get('arr').pushObject(A.create({
name: 'a'
}));
}
}
});
import Ember from 'ember';
import A from './AModel';
import computed from 'ember-computed';
import set from 'ember-metal/set';
import get from 'ember-metal/get';
export default Ember.Component.extend({
value: '',
arr: computed(() => []),
arrx: computed(() => []),
actions: {
addObjectToArr() {
get(this, 'arr').pushObject(A.create({
name: 'a'
}));
},
addPrimitivesToArr() {
get(this, 'arrx').pushObject('sss');
},
changeValue() {
set(this, 'value', get(this, 'value') + 's');
}
}
});
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
abc: '123'
});
<h1>Welcome to {{appName}}</h1>
<br>
<br>
{{my-component}}
{{my-component}}
{{another-component}}
{{outlet}}
<br>
<br>
another-component <br/> arrlen: {{arr.length}}
<button {{action "addObjectInArr"}}>addObjectInArr</button>
<br/>
<br/>
my-component <br/>
arrlen: {{arr.length}}
<button {{action "addObjectToArr"}}>addObjectToArr</button>
<br/>
arrxlen: {{arrx.length}}
<button {{action "addPrimitivesToArr"}}>addPrimitivesToArr</button>
<br/>
value: {{value}}
<button {{action "changeValue"}}>changeValue</button>
<br/>
<br/>
{
"version": "0.10.7",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "2.10.0",
"ember-data": "2.10.0",
"ember-template-compiler": "2.10.0",
"ember-testing": "2.10.0"
},
"addons": {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment