does the beforeShowContent method not execute in c...
# suitecommerce
v
does the beforeShowContent method not execute in child views?
s
no,i guess. bcoz childviews are instantiated by parent view not by childview itself.
v
oh right. but if i had to load a separate model in the child view, how would I do it?
t
Couldn’t you add the model you need as a dependency of the child view and load it within the view? Either that or load the model before you instantiate the child view and pass it in as a parameter when it’s being created?
s
If you're using page types, then your child view can just use something like this:
Copy code
, beforeShowContent: function beforeShowContent ()
  {
    return this.model.fetch()
  }
Although you should probably also pass in an AJAX request killer ID as well
If you're not using page types then we typically recommend you don't create the child view until the model fetch has completed, but you could probably just as easy add in a model fetch to the child view's
initialize()
method and then trigger a re-render after successfully fetching
Also I should point out that
beforeShowContent
as an event is, generally speaking, one introduced through the extensibility API. Prior to that we did generic Backbone events that triggered at the same time as the event in question; for example
this.model.on('change', this.render)
v
Thanks for the inputs @Steve Goldberg @TheAntman I managed to successfully get the data in the child view that I needed 👍