The apex.model namespace contains methods used to manage client side APEX data models. These models store data for display by UI components. See model for details.
This namespace contains functions to manage the lifecycle of a model:
- Use apex.model.create to create a model.
- Use apex.model.list to list all the existing models.
- Use apex.model.get to return an existing model.
- Use apex.model.release to release a model once you are done with it.
Models are reference counted so for every call to get or create you must call release. Failure to do so can result in unused models taking up memory. Typically the APEX region plug-in associated with the model will manage its life cycle.
There are also methods such as apex.model.save, apex.model.anyChanges, and apex.model.anyErrors that operate on multiple models.
Models can be arranged in a master detail configuration. This is done by providing the parentModel and parentRecordId options when creating the detail models. A single master model can have multiple kinds of detail models. For example projects can have tasks and members as details. Each kind of detail model has one or more model instances; each related to a record in the master model. Detail instance models share the same name and field configuration but each has a distinct instance id and different data. A model is uniquely identified by a model.ModelId, which in the case of a detail model contains the detail name and instance id. Detail models are cached so that data doesn't have to be fetched from the server unnecessarily. The view layer typically shows a view of the detail instance model that is associated with the current record of the master view. As the current record of the master changes the view layer changes the detail model instance the detail view is showing. The view layer will get a cached instance model if there is one and if not will create the instance model. The maximum number of detail instances to cache is controlled with the apex.model.getMaxCachedModels and apex.model.setMaxCachedModels functions. It is the least recently used model that is kicked out of the cache. Models that have changes are not destroyed unless apex.model.destroy is called.
A detail model can be a master to its own set of sub-detail models. This relationship can be nested to any depth.
- Since:
- 5.1
Functions
(static) addChangesToSaveRequest(pRequestData, pModelIdopt, pIncludeRelatedopt) → {function}
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
pRequestData |
object | An initial request object that will have all changes for the specified models added to it. | |
pModelId |
model.ModelId |
<optional> |
Model identifier as given in call to create or just a model name. See apex.model.list for how this parameter is used to select which models to operate on. |
pIncludeRelated |
boolean |
<optional> |
If true then any dependents of any selected models are included if they have changes. |
Returns:
- Type
- function
(static) anyChanges(pIncludeLocalopt, pModelIdopt, pIncludeRelatedopt) → {boolean}
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
pIncludeLocal |
boolean |
<optional> |
If true models that don't have a regionId will be included. |
pModelId |
model.ModelId |
<optional> |
Model identifier as given in call to create or just a model name. See apex.model.list for how this parameter is used to select which models to operate on. |
pIncludeRelated |
boolean |
<optional> |
If true then any dependents of any selected models are included in check |
Returns:
- Type
- boolean
(static) anyErrors(pIncludeLocalopt, pModelIdopt, pIncludeRelatedopt) → {boolean}
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
pIncludeLocal |
boolean |
<optional> |
If true models that don't have a regionId will be included. |
pModelId |
model.ModelId |
<optional> |
Model identifier as given in call to create or just a model name. See apex.model.list for how this parameter is used to select which models to operate on. |
pIncludeRelated |
boolean |
<optional> |
If true then any dependents of any selected models are included in check. |
Returns:
- Type
- boolean
(static) create(pModelId, pOptions, pDataopt, pTotalopt, pMoreDataopt, pDataOverflowopt) → {model}
Create a model with the given identity, options and optionally initial data. When you are done with the model you must call apex.model.release. Or if you are sure no one else is using it you can call apex.model.destroy.
Parameters:
Name | Type | Attributes | Description | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
pModelId |
model.ModelId | Model identifier. Must be unique for the page. Creating a model with an identifier that already exists will overwrite the existing model. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
pOptions |
object | Model options. All properties are optional unless specified otherwise.
Properties
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
pData |
array | object |
<optional> |
Initial data to add to the model. For table shape data it is an array of model.Record. For tree shape models it is a model.Node for the root. For record shape data it is a single model.Record. If null or not given there is no initial data. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
pTotal |
integer |
<optional> |
Total number of records in servers collection. Only applies for table shape models. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
pMoreData |
boolean |
<optional> |
If true there is more data available on the server for this model. If false pData contains all the data. If omitted or null determine if there is more data based on pData and pTotal. If pTotal is not given assume there is more data on server. Only applies for table shape models and only if paginationType is not "none". | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
pDataOverflow |
boolean |
<optional> |
If true there is more than the maximum allowed records for this model. Only applies for table shape models. |
Returns:
- Type
- model
(static) destroy(pModelId)
Destroy and remove a model by its identifier. This bypasses reference counting and caching. This method should not be used unless you are sure that no one else is using the model.
If pModelId is a string model name and there are one or more instances they will all be destroyed.
Parameters:
Name | Type | Description |
---|---|---|
pModelId |
model.ModelId | Model identifier as given in call to create. |
Example
Destroy the model with model id MyModel.
apex.model.destroy("MyModel");
(static) get(pModelId) → {model}
Parameters:
Name | Type | Description |
---|---|---|
pModelId |
model.ModelId | Model identifier as given in call to create. |
Returns:
- Type
- model
Example
Get access to a model with model id MyModel and release it when done.
var myModel = apex.model.get("MyModel");
// ... do something with myModel
apex.model.release("MyModel"); // release it when done
(static) getMaxCachedModels() → {integer}
Returns:
- Type
- integer
(static) list(pIncludeLocalopt, pModelIdopt, pIncludeRelatedopt) → {Array.<model.ModelId>}
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
pIncludeLocal |
boolean |
<optional> |
If true models that don't have a regionId will be included. |
pModelId |
model.ModelId |
<optional> |
Model identifier as given in call to create or just a model name. |
pIncludeRelated |
boolean |
<optional> |
If true then any dependents of any listed models are included. |
Returns:
- Type
- Array.<model.ModelId>
(static) release(pModelId)
Release a model if it is not being used but may be used again in the future. This allows the model to be destroyed if needed to conserve memory.
Models are reference counted. For every call to get or create a call to release with the same model id is required. When the reference count is zero the model is destroyed unless it is changed or if it has a parent model, in which case it is cached.
Parameters:
Name | Type | Description |
---|---|---|
pModelId |
model.ModelId | Model identifier as given in call to create. |
Example
Get access to a model with model id MyModel and release it when done.
var myModel = apex.model.get("MyModel");
// ... do something with myModel
apex.model.release("MyModel"); // release it when done
(static) renameInstance(pOldId, pNewInstance)
Parameters:
Name | Type | Description |
---|---|---|
pOldId |
||
pNewInstance |
(static) save(pRequestDataopt, pOptionsopt, pModelIdopt, pIncludeRelatedopt) → {promise}
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
pRequestData |
object |
<optional> |
An initial request object that will have all changes for the specified models added to it. |
pOptions |
object |
<optional> |
Options to pass on to apex.server.plugin API. |
pModelId |
model.ModelId |
<optional> |
Model identifier as given in call to create or just a model name. |
pIncludeRelated |
boolean |
<optional> |
If true then any dependents of any selected models are included in check. |
Returns:
- Type
- promise
(static) setMaxCachedModels(n)
Parameters:
Name | Type | Description |
---|---|---|
n |
integer | Number of unreferenced, unchanged detail instance models that will be kept. |