Framework managed versus view managed content for coaches
At run time, the content inside a content box of a coach can be managed by the runtime
framework or by the view. By default, the framework manages the content, but if you want to code
your own custom behavior, you can choose that the content be managed by the view.
There are times when you might want to override the default behavior of the framework when a coach is rendered. For example, when a view is bound to data that is an array, the framework creates a view for each index element in the array. You might want to create views for a different set of elements, in which case you can choose the option to let the view manage its own content.
The option for a view to manage its own content is set as a property on a content box at design
time. To set the option:
- Open the view, and switch to Layout.
- Click the content box on the editor.
- Under Properties, click the option The View will manage its own content.
- You can write your custom code in a callback method such as
load()
to manage the content. For more information, see View managed coaches
Framework managed content
When the content of the view is managed by the framework, the runtime framework handles the content of a content box as follows:- If the content box inherits a data binding that is an array, the framework clones the DOM node of the content box n times where n is the number of elements of the data binding array. A view is created inside the content box for each index element in the array.
- If the content box inherits a data binding that is not an array, the framework creates views for the enclosed contents.
View managed coaches
When the view manages its own content, the view is responsible for handling the content inside
the content box. The following is the typical scenario:
- Initialize and render the sub-views:
- If the content box inherits a data binding that is an array, the view typically does the
following in one of its callback methods, for example
load()
:- The view deeply clones the DOM node of the content box n times, where n is the number of elements of the data binding array.
- Performs initialization logic as required, for example add/remove/update/decorate the content of the cloned node.
- Invokes the framework method
this.context.createView()
- If the content box inherits a data binding that is not an array, the view does the following in
one of the its callback methods, for example
load()
:- Performs initialization logic as required
- Invokes the framework method
this.context.createView()
- If the content box inherits a data binding that is an array, the view typically does the
following in one of its callback methods, for example
- Add/delete content dynamically:
- Add content (for example add new row in table)
- Create the new binding object and add it to the binding array using DataBinding API
- Invoke the framework method
this.context.createView()
- Delete content (for example delete row in table)
- delete the binding object for that row directly or indirectly
- Invoke the framework method
this.context.deleteView()
- Add content (for example add new row in table)