ember.js - How to change controller property from component? -


i have property in controller. want use component update controller property. usual component parameter passing works when i'm using text field guides say, in case, i'm changing value in code, not input fields. binding seems broken.

what method similar propertydidchange() or notifypropertychange() should use accomplish this? can provide simple example know make method call?

personalities controller

`import ember 'ember'`  personalitiescontroller = ember.arraycontroller.extend    eivalue: ->     if params.name       params.name.charat(0)     else       'e'    nsvalue: ->     if params.name       params.name.charat(1)     else       'n'    tfvalue:  ->     if params.name       params.name.charat(2)     else       't'    pjvalue:  ->     if params.name       params.name.charat(3)     else       'p'    type: (->     this.get('eivalue') + this.get('nsvalue') + this.get('tfvalue') + this.get('pjvalue')   ).property('eivalue', 'nsvalue', 'tfvalue', 'pjvalue')    typechanged: ((model, type)->     ember.run.once(this, 'routetopersonality')   ).observes('type')    routetopersonality: ->     this.get('controller').transitiontoroute('personality', this.get('type'))  `export default personalitiescontroller` 

personalities template

%dichotomy-selector type=type 

component

`import ember 'ember'`  dichotomyselectorcomponent = ember.component.extend   eivalue: 'e'   nsvalue: 'n'   tfvalue: 't'   pjvalue: 'p'    type: (->     newvalue = this.get('eivalue') + this.get('nsvalue') + this.get('tfvalue') + this.get('pjvalue')     this.set('controller.type', newvalue)   ).property('eivalue', 'nsvalue', 'tfvalue', 'pjvalue')    actions:      toggleei: ->       eivalue = this.get('eivalue')       if eivalue == 'e'         this.set('eivalue', 'i')       else if eivalue == 'i'         this.set('eivalue', 'e')      togglens: ->       nsvalue = this.get('nsvalue')       if nsvalue == 'n'         this.set('nsvalue', 's')       else if nsvalue == 's'         this.set('nsvalue', 'n')      toggletf: ->       tfvalue = this.get('tfvalue')       if tfvalue == 't'         this.set('tfvalue', 'f')       else if tfvalue == 'f'         this.set('tfvalue', 't')      togglepj: ->       pjvalue = this.get('pjvalue')       if pjvalue == 'p'         this.set('pjvalue', 'j')       else if pjvalue == 'j'         this.set('pjvalue', 'p')  `export default dichotomyselectorcomponent` 

you should able use this.set("controller.property", value) in method inside component, per docs here: http://emberjs.com/api/classes/ember.component.html#property_controller

edit september 2016 answer has been victim of ongoing evolution of ember, , associated changes in best practices. amazing see how different ember 1.5 years ago. old answer has been totally rejected community evidenced votes (negative type this), in fact don't think works anymore. of mid-2016 in ember 2.x accepted answer question create action in controller changes property, pass action component, , call action when value changes on component. can use action helper pass regular method instead of action, , use component life cycle hooks detect changes in component instead of using observer or computed property. use service instead. more changes on way, sure.

for future readers, questions need research ember make sure filter results time, want results within last year.


Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -