The object describing events in the template is a regular JavaScript object. The property names of this object are the names of the events, and the values are the functions that will be called when the event occurs.
Event names are constructed in different ways depending on the type of event:
.constuct
suffix.
The full path to the item actually represents the fully qualified name of the object's property, starting
from the root of the model. The []
suffix is used to indicate an array item.
Syntax:
Those events have fixed names.
Model.load
- model is downloaded.Model.unload
- model is uploaded. No action is possible anymore. Most often used
to unsubscribe from events on the global event bus.
Model.saved
- model is saved.Model.beforeSave
- before saving.Arguments for the model events:
this
- data model root (IRoot).model
- data model root (IRoot).caller
- reference to the data model root (IRoot) of the caller. For example,
if this is a dialog model, then the caller
will be a reference to the model
from which this dialog was called. Can be used to interact with the caller. For
Model.saved
, Model.save
events, the value will always be
undefined
.
.construct
- the object is created. The event name prefix represents the name of
the object type. In the handler of this event, you can add new properties to the created item.
However, it is better to use the (properites) mechanism for this purpose.
.change
- property value has been changed. The event name prefix is the full path to the property in the data model.
.changing
- the property value will be changed. The event name prefix is the full path to the property in the
data model. It is possible to undo the changes.
Arguments for the .construct
event:
this
- data model root (IRoot).elem
- created item.prop
- the name of the property of the parent item
to which the created object will be assigned. Makes sense for
the items creating handlers in a MapObject
.
.changing
, .change
:
this
- data model root (IRoot).elem
- item.newValue
- the new value of the property.oldValue
- the old value of the property.prop
- the name of the property to change..changing
event:
Boolean
- strict false
value. Cancels an attempt to change
the property value. Any other value allows changes.
The name prefix for all array events is the full path to the property in the model.
[].adding
- before adding the item to the array.[].add
- the item is added to the array.[].change
- the array item has been changed.[].remove
- the item has been removed from the array.[].select
- the array item is selected.
Please note! The events will be generated only when platform tools are used to manipulate
the arrays. If the array is changed using standard methods (for example, push
,
splice
), then no events will be generated.
Arguments for the array events:
this
- data model root (IRoot).arr
- modifiable array.elem
- new or deleted item..adding
event.
Boolean
- strict false
value. Cancels the operation of adding an item to the array.The events described above are inline events. However, no one forbids the use of custom events, which can more accurately describe the business logic of the application.
Such events are generated by the $emit method of the root object (IRoot)
and can have an arbitrary name (of course, not overlapping with system names). The $emit
method can also generate system events.
Please note! The event model in the system is associated with data, not with elements of the user interface. In other words, events occur when data changes. The occurrence of events bears no relation to the user interface. In fact, there may be no user interface at all.