class sap.ui.model.json.JSONModel

Visiblity: public
UX Guidelines:
Implements:
Available since: N/A
Module: sap/ui/model/json/JSONModel
Application Component: CA-UI5-COR

Model implementation for the JSON format.

This model is not prepared to be inherited from.


Constructor

Constructor for a new JSONModel.

The observation feature is experimental! When observation is activated, the application can directly change the JS objects without the need to call setData, setProperty or refresh. Observation does only work for existing properties in the JSON, it cannot detect new properties or new array entries.

new sap.ui.model.json.JSONModel(oData?, bObserve?)
Param Type Default Value Description
oData? object string

Either the URL where to load the JSON from or a JS object

bObserve? boolean

Whether to observe the JSON data for property changes (experimental)


Methods Overview

Method Description
dataLoaded

Returns a Promise of the current data-loading state. Every currently running sap.ui.model.json.JSONModel#loadData call is respected by the returned Promise. This also includes a potential loadData call from the JSONModel's constructor in case a URL was given. The data-loaded Promise will resolve once all running requests have finished. Only request, which have been queued up to the point of calling this function will be respected by the returned Promise.

sap.ui.model.json.JSONModel.extend

Creates a new subclass of class sap.ui.model.json.JSONModel with name sClassName and enriches it with the information contained in oClassInfo.

oClassInfo might contain the same kind of information as described in sap.ui.model.ClientModel.extend.

getJSON

Serializes the current JSON data of the model into a string.

sap.ui.model.json.JSONModel.getMetadata

Returns a metadata object for class sap.ui.model.json.JSONModel.

getProperty

Returns the value for the property with the given path and context.

loadData

Load JSON-encoded data from the server using a GET HTTP request and store the resulting JSON data in the model. Note: Due to browser security restrictions, most "Ajax" requests are subject to the same origin policy, the request can not successfully retrieve data from a different domain, subdomain, or protocol.

setData

Sets the data, passed as a JS object tree, to the model.

setJSON

Sets the data, passed as a string in JSON format, to the model.

setProperty

Sets a new value for the given property sPropertyName in the model. If the model value changed all interested parties are informed.

dataLoaded

Returns a Promise of the current data-loading state. Every currently running sap.ui.model.json.JSONModel#loadData call is respected by the returned Promise. This also includes a potential loadData call from the JSONModel's constructor in case a URL was given. The data-loaded Promise will resolve once all running requests have finished. Only request, which have been queued up to the point of calling this function will be respected by the returned Promise.

sap.ui.model.json.JSONModel.extend

Creates a new subclass of class sap.ui.model.json.JSONModel with name sClassName and enriches it with the information contained in oClassInfo.

oClassInfo might contain the same kind of information as described in sap.ui.model.ClientModel.extend.

Param Type DefaultValue Description
sClassName string

Name of the class being created

oClassInfo object

Object literal with information about the class

FNMetaImpl function

Constructor function for the metadata object; if not given, it defaults to the metadata implementation used by this class

getJSON

Serializes the current JSON data of the model into a string.

sap.ui.model.json.JSONModel.getMetadata

Returns a metadata object for class sap.ui.model.json.JSONModel.

getProperty

Returns the value for the property with the given path and context.

Param Type DefaultValue Description
sPath string

The path to the property

oContext sap.ui.model.Context

The context which will be used to retrieve the property

loadData

Load JSON-encoded data from the server using a GET HTTP request and store the resulting JSON data in the model. Note: Due to browser security restrictions, most "Ajax" requests are subject to the same origin policy, the request can not successfully retrieve data from a different domain, subdomain, or protocol.

Param Type DefaultValue Description
sURL string

A string containing the URL to which the request is sent.

oParameters object string

A map or string that is sent to the server with the request. Data that is sent to the server is appended to the URL as a query string. If the value of the data parameter is an object (map), it is converted to a string and url-encoded before it is appended to the URL.

bAsync boolean true

By default, all requests are sent asynchronous. Do not use bAsync=false because synchronous requests may temporarily lock the browser, disabling any actions while the request is active. Cross-domain requests do not support synchronous operation.

sType string GET

The type of request to make ("POST" or "GET"), default is "GET". Note: Other HTTP request methods, such as PUT and DELETE, can also be used here, but they are not supported by all browsers.

bMerge boolean false

Whether the data should be merged instead of replaced

bCache boolean true

Disables caching if set to false. Default is true.

mHeaders object

An object of additional header key/value pairs to send along with the request

setData

Sets the data, passed as a JS object tree, to the model.

Param Type DefaultValue Description
oData object

the data to set on the model

bMerge boolean false

whether to merge the data instead of replacing it

setJSON

Sets the data, passed as a string in JSON format, to the model.

Param Type DefaultValue Description
sJSON string

the JSON data to set on the model

bMerge boolean false

whether to merge the data instead of replacing it

setProperty

Sets a new value for the given property sPropertyName in the model. If the model value changed all interested parties are informed.

Param Type DefaultValue Description
sPath string

path of the property to set

oValue any

value to set the property to

oContext object

the context which will be used to set the property

bAsyncUpdate boolean

whether to update other bindings dependent on this property asynchronously