ember.js - How can I send a message / call a method on all itemController children instances in Ember? -
i'm trying use "buffered proxy" pattern on collection of items in form hasmany model. when complete, i'm trying have "save" button, triggers save action, allow me save as-yet unsaved changes i've made. more info on bp in ember:
http://coryforsyth.com/2013/06/27/ember-buffered-proxy-and-method-missing/
i can work fine top level model attribute, i'm confused how tell non-singleton itemcontrollers want them save buffers, able call grandparent save whole enchilada. hoping i'd able parent array controller:
actions: { savestuff: function() { // possible? this.get('allthenonsingletonitemcontrollerchildren').send('savethosebuffers'); } }
child controller:
savethosebuffers: function() { var grandparent = this.get('parentcontroller').get('parentcontroller'); this.applybufferedchanges(); grandparent.saveentirerecord(); // not sure how work yet - can't use 'needs' because none of these controllers singletons. }
grandparent:
saveentirerecord: function() { this.get('model').save().then(function() { //other stuff; } }
view like:
{{#each stuff in childitems itemcontroller="childcontroller"}} {{input type="text" value=stuff.name}} {{/each}} <button {{action 'savestuff'}}>save</button>
nothing in docs or has revealed incantations this.
update:
based on suggestion, tried:
children = this.get('content'); children.foreach(function(child) { child.send('savethosebuffers'); });
but received:
"uncaught error: attempted handle event savethosebuffers
on while in state root.loaded.saved."
update 2:
versions:
debug: ember : 1.5.0-beta.2 ember.js:3496 debug: ember data : 1.0.0-beta.7+canary.b45e23ba ember.js:3496 debug: handlebars : 1.3.0 ember.js:3496 debug: jquery : 1.9.1 ember.js:3496
update 3:
tried getting access subcontrollers using:
var children = this.get('_subcontrollers');
that returns empty array, regardless of itemcontroller set (in arraycontroller or in each loops using itemcontroller=)
update 4:
i've created jsfiddle shows i'm attempting possible using _subcontrollers:
however, works doing setup in route using setupcontroller, don't see how can use in application (the controller in question cannot named same model, it's 1 'mode' of viewing/editing model using {{render}} , uses async hasmany relationship.)
none of above methods worked (hopefully buffered proxy fleshed out , officially support/integrated ember someday soon, not saving nested models until buttons pushed common use case) wound following in parent controller, job:
childmodels = this.get('child.content.content'); childmodels.foreach(function(child) { child.rollback(); // or .save() });
Comments
Post a Comment