Passing Parameters to Views and SerializeData
Learn how to add a delay to display our contact list until all the contacts are loaded.
We'll cover the following
Let’s take a step back and think about our app for a second. Our List
controller displays a loading view saying that data is being loaded with an artificial delay. However, that’s not true. We need some way to display a different loading message for our List
submodule.
We could simply add a new template with a different loading message and provide the proper template when instantiating the view, as we saw earlier. It would work, but it would be a dirty hack.
Given that our loading view is intended to be shared across the application, providing the title and message to display when we instantiate the view would be better. In other words, we need to be able to provide parameters to our loading view.
Using the intialize
function
We’ll need to store the title
and message
attributes in the view (if any are given) by using an initialize
function. However, how do we display them in the template? Well, Marionette calls the serializeData
function to provide data to the template. We can write our own version to provide these new attributes:
Get hands-on with 1400+ tech skills courses.