Skip to content

Instantly share code, notes, and snippets.

@n1ru4l
Last active May 23, 2017 16:04
Show Gist options
  • Save n1ru4l/a1ae6842f5d62604b67a71e43afc887d to your computer and use it in GitHub Desktop.
Save n1ru4l/a1ae6842f5d62604b67a71e43afc887d to your computer and use it in GitHub Desktop.
array not updating
import Ember from 'ember';
import {
times,
constant
} from 'lodash';
const {
get,
set,
Component,
on,
A: EArray,
} = Ember;
export default Component.extend({
answers: null,
answerCheckedStates: null,
onInit: on(`init`, function () {
const lengthAmount = this.get(`answers.length`)
const answerCheckedStates = times(lengthAmount, () => false)
this.set(`answerCheckedStates`, answerCheckedStates)
}),
actions: {
toggleStatus(index) {
const currentValue = get(this, `answerCheckedStates.${index}`)
console.log(`Current value`, currentValue)
set(this, `answerCheckedStates.${index}`, !currentValue)
const changedValue = get(this, `answerCheckedStates.${index}`)
console.log(`Changed value`, changedValue)
}
}
});
import Ember from 'ember';
const {
A: EArray,
} = Ember;
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
answers: EArray([
{ id: 1, value: `Tomato` },
{ id: 2, value: `Oranges` },
{ id: 3, value: `Pineapple` },
{ id: 4, value: `Sushi` },
])
});
import Ember from 'ember'
export function nthChild(params/*, hash*/) {
return params[0][params[1]]
}
export default Ember.Helper.helper(nthChild)
{{some-component
answers=answers
}}
{{#each-in answers as |index answer|}}
{{#paper-checkbox
value=(nthChild answerCheckedStates index)
onChange=(action "toggleStatus" index)
}}
{{answer.value}}
{{/paper-checkbox}}
{{/each-in}}
{
"version": "0.12.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": "2.12.0",
"ember-template-compiler": "2.12.0",
"ember-testing": "2.12.0"
},
"addons": {
"ember-data": "2.12.1",
"ember-lodash": "4.17.4",
"ember-paper": "1.0.0-alpha.19"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment