Using the Oracle JET Common Model and Collection Framework
The Oracle JET Common Model and Collection API provides a collection-of-records object model that includes classes for bringing external data into an Oracle JET application and mapping the data to the application’s view model.
Topics:
About the Oracle JET Common Model and Collection API
The Oracle JET Common Model and Collection API provides a collection-of-records object model that includes the following classes:
-
oj.Model: Represents a single record from a data service such as a REST service -
oj.Collection: Represents a set of data records and is a list ofoj.Modelobjects of the same type -
oj.Events: Provides methods for event handling -
oj.KnockoutUtils: Provides methods for mapping the attributes in aoj.Modeloroj.Collectionobject to Knockout observables for use with component ViewModels
oj.Model and oj.Collection include client-side API that provides one way to bring external data into an Oracle JET application. oj.KnockoutUtils provides the map() method to map the attributes in a model object or the attributes of all models in a collection object to the application's view data model.
About Oracle JET Data Binding and Knockout
Knockout provides bindings between components as well as binding data from a ViewModel to components or HTML elements in an Oracle JET application. Knockout is an integral part of Oracle JET's toolkit and is included in the Oracle JET distribution.
The Oracle JET Model and Collection API includes the KnockoutUtils class which contains the map() method to convert the attributes in a model object (or the attributes of all models in a collection object) into Knockout observables for use with components' ViewModels.
The example below maps the data collection to the tasks ViewModel.
renderTaskViews = function(tasksData) {
this.tasks = oj.KnockoutUtils.map(data);
}
To utilize the data model in Oracle JET applications, Oracle JET provides custom elements which support Knockout variables in the data attribute. For additional information about working with Oracle JET UI components, see Understanding Oracle JET User Interface Basics.
<oj-table data="[[dataSource]]"> </oj-table>
For additional information about Knockout, see http://www.knockoutjs.com.
Using the Oracle JET Common Model and Collection API
To use a Model or Collection class, an application must extend oj.Model or oj.Collection to create a foundation object to represent a data record or list of records from its data service. The application provides the data service's URL used for fetching and updating task records (when a task record's ID is appended), along with various options giving users the ability to map data service records to their client-side ViewModel and vice versa.
To use the Oracle JET Common Model and Collection API:
For a complete list of Oracle JET Common Model and Collection API properties and functions, see the oj.Model and oj.Collection API documentation.