Life-Time Handlers
config()
This method returns the initial UI configuration of a view:
init()
The method is called once when a view is rendered. It is a good place to load some common data or to change the initial UI configuration of a view returned by config().
init() receives two parameters:
view (Webix view) - the view UI,
url - the app URL as an array.
Each array element of url is an object that contains three properties:
page - the name of the URL element,
params - parameters that you can pass with the URL,
index - the index of the URL element (beginning from 1).
Let's use init() to change the state of a control in a simple UI:
This is how you can load data to a Jet class view:
urlChange()
urlChange() is called every time the app URL is changed. It reacts to the change in the URL after !# [1].
When urlChange is called
if a URL segment is changed, urlChange() is called for the view that is rendered from that segment and for its parent
Consider the following example. The initial URL is:
If you change it to:
urlChange() will be called for preview and demo. demo is not reconstructed. Such approach allows preserving parts of UI not affected by navigation, which improves performance and UX of the app. It is especially important if you have some complex widget in the parent view and do not want to fully reconstruct/reload it on subview navigation.
if a URL parameter is changed, urlChange() is called for the view-owner of the parameter and for its kids.
For example, if you have the view structure like the following:
and set the id param for layout via setParam or show, urlChange() of layout, demo, and details will be called.
Method parameters
The urlChange method receives two parameters:
view - the Webix widget inside the Jet view class
url - the URL as an array of URL elements
Example
urlChange() can be used to restore the state of the view according to the URL, e.g.:
ready()
ready() is called when the current view and all its subviews have been rendered. For instance, if the URL is changed to a/b, the order in which view class methods are called is the following:
ready() receives two parameters:
view - the Webix widget inside the Jet view class
url - the URL as an array of URL elements
Here's how you can use ready(). There is a bigger form that includes a smaller form. To fill both forms at the same time you should wait till the subform is fully rendered:
destroy()
destroy() is called only once for each class instance when the view is destroyed (closed and no longer present in the app URL).
E.g. you can use destroy() to detach event listeners that will not be destroyed automatically or clean some temporary data.
Last updated