Last active
October 1, 2018 23:00
-
-
Save theoldcounty/2ba652b74684ce31238c7409c4720af5 to your computer and use it in GitHub Desktop.
Parent / Child Component Communication
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Component from '@ember/component'; | |
import { action, computed, observes } from '@ember-decorators/object'; | |
export default class extends Component { | |
selectedItems = []; | |
_cbState = false; | |
_changeCounter = 0; | |
parent = false; | |
@observes('changeCounter') | |
watchForChanges() { | |
if (!this.parent) return; | |
if (this._changeCounter === this.changeCounter) return; | |
this.set('_changeCounter', this.changeCounter); | |
// this.set('cbState', false); | |
} | |
@computed('parentValue') | |
get cbState() { | |
console.log(this.parentValue, this._cbState); | |
if (this.parentValue) { | |
this._cbState = false; | |
} | |
return this._cbState; | |
} | |
set cbState(value) { | |
this._cbState = value; | |
} | |
@action | |
myChangeAction(nextValue) { | |
this.set('cbState', nextValue); | |
//console.log("type", this); | |
console.log(this.group) | |
if (nextValue) { | |
this.get('selectedItems').pushObject(this); | |
} else { | |
this.get('selectedItems').removeObject(this); | |
} | |
console.log("this.get('selectedItems')", this.get('selectedItems')) | |
if (this.trackChange) { | |
this.trackChange(); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Component from '@ember/component'; | |
import { action, computed } from '@ember-decorators/object'; | |
export default class extends Component { | |
changeCounter = 0; | |
@action | |
trackChange() { | |
this.set('changeCounter', this.changeCounter + 1); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
export default Ember.Controller.extend({ | |
appName: 'Ember Twiddle', | |
items : [{ | |
"title" : "burger", | |
"id": "bk2", | |
"subgroup" : [ | |
{"name" : "tomato", "id": "tomo2"}, {"name" : "lettuce", "id": "let2"}, {"name" : "pickle", "id": "pickl3"}] | |
}, | |
{ | |
"title" : "kebab", | |
"id": "kb2", | |
"subgroup" : [{"name" : "ketchup", "id": "ketchu2"}, {"name" : "chilli", "id": "chilli2"}] | |
}] | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
export function not(params/*, hash*/) { | |
return !params[0]; | |
} | |
export default Ember.Helper.helper(not); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
body { | |
margin: 12px 16px; | |
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; | |
font-size: 12pt; | |
} | |
.checkboxhandler{ | |
position: relative; | |
margin-left: 10px; | |
margin-bottom:10px; | |
border: 1px solid red; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"version": "0.15.0", | |
"EmberENV": { | |
"FEATURES": {} | |
}, | |
"options": { | |
"use_pods": false, | |
"enable-testing": false | |
}, | |
"dependencies": { | |
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js", | |
"ember": "3.4.1", | |
"ember-template-compiler": "3.4.1", | |
"ember-testing": "3.2.2" | |
}, | |
"addons": { | |
"ember-decorators": "2.0.0" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment