How to pass params from parent controller to child controller?

There must be a way, when calling actionContext.composite.done() to add some params that the child Mojits can read.   The actionContect.params object seems to be read-only.  I must be missing something, but I haven't found any example.  Using broadcast/listen in the binders seem overkill since it would imply displaying an empty or fake child only for it to get to listen to the parent binder to tell it to refresh itself, this time for good.  It would take too many resources.   I would like to do something like this:

ac.composite.done(data, {params:{route:{idChild:2}}} which would get merged with the rest of the parameters so that the child Mojito reads it just like any other argument. 

In my case, I don't know idChild beforehand, I will only know about it once I fetch the parent record and, from that, read the reference to the child record.  I could communicate them at the binder level, but it seems that it would take too many trips and, moreover, I would have to plan for an empty view to show while it gets refreshed.

3 Replies
  • Actually, it is the other way around.  I need the parent to pass data to the child.  Basically, the URL has the primary key for the parent record.  The parent record has references to additional information in other tables.  Once the parent record is fetched, I need to pass those references to the child mojits so they know what they are supposed to show. 

    A few of the child table data is useful on its own so there are routes with parameters to fetch those separately.  I could use the same standalone Mojit as child to the parent if only I could add the id on the routes so it would show in the child placeholder just the same as in the standalone page.

    I could do an SQL View to fetch the parent record already joined to the child records, but I already have child mojits for most of them so it seems a waste.

    Currently, I let the child mojit load with no data and then refresh after listening to their keys broadcast from the parent, which is wasteful in performance, though it allows me to re-use the child mojits.

  • I'm happy to report that I'm an idiot.  There is a way, using ac.composite.execute.  This, however, seems to be a little overkill since I don't really mean to run any child with any params.  Managing the response and merging it with that of the parent is also not trivial.  It would be nice to have an easier way to do it.
  • Please see my other post for a suggested way to handle this, including code.

Recent Posts

in Yahoo! Mojito