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:
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 RESTful web service
oj.Collection: Represents a set of data records and is a list of oj.Model objects of the same type
oj.Events: Provides methods for event handling
oj.KnockoutUtils: Provides methods for mapping the attributes in a oj.Model or oj.Collection object 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.
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 framework 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 bind UI components in Oracle JET applications to the data model, the Oracle JET components support Knockout's data-bind attribute, both for standard and Oracle JET UI components. For additional information about working with Oracle JET UI components, see Understanding Oracle JET User Interface Basics.
<ul data-bind="foreach: tasks"> <li data-bind="text: name"></li> </ul> <div data-b
For additional information about Knockout, see http://www.knockoutjs.com.
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.